Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 15th, 2007, 6:11 PM   #1
bluebarca
Newbie
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0 bluebarca is on a distinguished road
socket Multithreading - & - Obtaining the IP of a client!

hey everybody, hope u r all having a gr8 time!
i have 2 questions:
1st i have a socket lets a call it x that runs on a pc that acts as a server, when multiple clients try to connect and send data to this socket will there be a problem ( will the java code multithread automatically and manage) or should i implement my multithreading.

2nd when one of the users sends an input stream to the server ... is there a method so as i can obtain the IP address of this user ?


i would really appreciate your help guys !
bluebarca is offline   Reply With Quote
Old Nov 15th, 2007, 7:25 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: socket Multithreading - & - Obtaining the IP of a client!

C#, which is quite similar to Java in many ways, supports asynchronous I/O. I'd expect Java to offer similar functionality. Basically, the way it works is you call a method to begin an operation, and supply this method with a reference to (ie, the address of) a 'callback method'. This callback method is invoked when the operation is complete, and you can do whatever you like, such as raising events or what have you.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Nov 15th, 2007, 8:58 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: socket Multithreading - & - Obtaining the IP of a client!

<off-topic>
Welcome to the forum. Please read the rules. I refer specifically to this part:
Quote:
All posts are strongly encouraged to be in full-sentence English. Please do not use "leet" speak or "chatroom" speak. It makes what you're saying hard to understand, especially for those of us who aren't native English speakers.
For the most part, we're mature, big boys and girls here. Have a great time in our community.
</off-topic>
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 16th, 2007, 3:37 AM   #4
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
Re: socket Multithreading - & - Obtaining the IP of a client!

Quote:
Originally Posted by bluebarca View Post
1st i have a socket lets a call it x that runs on a pc that acts as a server, when multiple clients try to connect and send data to this socket will there be a problem ( will the java code multithread automatically and manage) or should i implement my multithreading.
First, this part:
Quote:
Originally Posted by bluebarca View Post
( will the java code multithread automatically and manage)
The operating system takes care of this. It will create seperate buffers for

For the rest, you have two choices:
1) Use blocking code and threads
2) Use Java's Non-blocking Facilities

Either way, you are going to end up with a seperate Socket (or SocketChannel) for each user that connects to the server. This abstracts the fact that you might have several connections.

ex.
ServerSocket.accept() returns a Socket,
ServerSocketChannel.accept() returns a SocketChannel

You can pass those to a thread that handles the connection, or if you are using non-blocking I/O, you can read from the socket and go on if not enough data was sent.

Quote:
Originally Posted by bluebarca View Post
2nd when one of the users sends an input stream to the server ... is there a method so as i can obtain the IP address of this user ?
For sockets, use:
String address = ((InetSocketAddress)socket.getRemoteSocketAddress()).getHostName();

For socket channels, use:
String address = ((InetSocketAddress)socketChannel.socket().getRemoteSocketAddress()).getHostName();
Harakim is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java socket Server compile errors.. n3o_X Java 3 Nov 18th, 2007 12:39 AM
Java Socket As Client Inly Receives One Msg ^^vampire^^ Java 2 Aug 23rd, 2007 6:46 PM
Determine when client socket request has been accepted. hoffmandirt Java 8 Oct 6th, 2006 9:50 AM
Python FTP Client Wrapper Sane Python 6 Jun 22nd, 2006 9:44 PM
Socket Server hbe02 C++ 19 May 23rd, 2006 10:14 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC