![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 1
Rep Power: 0
![]() |
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 ! |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#3 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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:
</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 |
|
|
|
|
|
|
#4 | ||
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
Re: socket Multithreading - & - Obtaining the IP of a client!
Quote:
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:
String address = ((InetSocketAddress)socket.getRemoteSocketAddress()).getHostName(); For socket channels, use: String address = ((InetSocketAddress)socketChannel.socket().getRemoteSocketAddress()).getHostName(); |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |