September 07, 2010, 05:10:33 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Basics on the Socket and SocketServer classes  (Read 1557 times)
0 Members and 1 Guest are viewing this topic.
The Soul
Member
*

Reputation: 2
Offline Offline
Posts: 12
Referrals: 1

Awards
« on: August 22, 2009, 04:41:27 PM »

I've gotten the A from a friend once again. He created a tutorial on using sockets though this'll be completely different.

First we'll import these two packages, enabling us to use certain classes (e.g Socket, ServerSocket, etc):
Code:
import java.net.*;
import java.net.*;
import java.io.*;

Now that we've imported these packages, we can use them.

Let's start with creating a new instance of the Socket class:
Code:
SocketServer socketserv = new SocketServer(5555);
The 'new' keyword makes it so you'll no longer have to call methods and what not from 'SocketServer', and now you can just use the object 'socketserv'. The integer will make it so the socketserv will only allow the connection from the port '5555'.

There are two very important methods that I'm going to explain right now, and they are:
accept() - accepts the connection.
close() - closes the connection.

There are others but I won't go into detail about them in this tutorial. More explanation will be put into this tutorial later on.
Logged
Javaforums.net :: a community about Java software development.
« on: August 22, 2009, 04:41:27 PM »

Your Ad Here
 Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #1 on: August 22, 2009, 04:54:48 PM »

Nice, glad your back : ) !

One of the many examples with the socket class: http://www.engineeringser...one+way+chat-t2338.0.html
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
korn
Junior Member
*

Reputation: 0
Offline Offline
Posts: 2
Referrals: 0

Awards
« Reply #2 on: October 09, 2009, 03:14:14 PM »

Thank you.
« Last Edit: October 09, 2009, 03:18:35 PM by korn » Logged
AdnanAhsan
Member
*

Reputation: -1
Offline Offline
Posts: 15
Referrals: 0

Awards
« Reply #3 on: October 25, 2009, 03:31:25 AM »

i am also intending to program some client/server programs for intranet and internet :)
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #4 on: November 02, 2009, 06:24:08 AM »

i am also intending to program some client/server programs for intranet and internet :)

if you need any help just open a topic and i'll see what i can do
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
   

Your Ad Here
 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.315 seconds with 38 queries.

Google visited last this page September 03, 2010, 03:36:04 PM