Results 1 to 10 of 10
Thread: Are 2 Sockets Required?
- 12-02-2011, 02:38 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Are 2 Sockets Required?
I am currently creating a server and client programs which both can send requests to each other. Therefore, the Server may ask for some
information from the client, and the client can ask for information from the server at the same time. Thus asking and responding may happen concurrently on different threads.
For me to program this, do I require 2 sockets? Note I am not asking whether a socket is bidirectional! A socket is bidrectional. What I
am asking is that for a server and client to send requests and respond to requests at the same time, is it required to use 2 sockets, or is there a way where you can just use one?
Thanks in advanced
Rewry
- 12-02-2011, 02:43 PM #2
Re: Are 2 Sockets Required?
There are two streams for a socket that should allow communiations both ways with the same socket connection.
Read from the input and write to the output.
- 12-02-2011, 02:49 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Re: Are 2 Sockets Required?
How can It be done? I know that a socket is bidirectional (it has two streams) The server and client have 2 functionality. Let me try and illustrate the cases :
Funcntion 1: When Server sends a request to client and client responds:
Server --> client
Server <-- client
Function 2: When client sends a request to server and server responds:
Server <-- client
Server -> client
Now these functions can happen at the same time
Do I need 2 sockets for this?
- 12-02-2011, 02:57 PM #4
Re: Are 2 Sockets Required?
This is backwards to me. Servers wait for connections from clients and respond to them. There is no way for a server to connect to a client because a client is not waiting for a connection with a ServerSocket.When Server sends a request to client
If a client connects to a server, it sends data to the server on the output stream and reads on the input stream.
When a server gets a connection from a client, it reads the clients output on the inputstream and sends data to the client on the socket's outputstream.
I think that the client can send data to the server at the same time as the server is sending data to the client.
You would only need one socket.
- 12-02-2011, 03:53 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Re: Are 2 Sockets Required?
Yes you are correct in that regard, but what if the server would like to send data which the client requested AND send a notification to the client at the same time?
Originally Posted by Norm;249192
I think that the client can send data to the server at the [B
- 12-02-2011, 03:55 PM #6
Re: Are 2 Sockets Required?
Can the two messages be sent one after the other on the same stream
or do you think that they must be sent at the same time on separate streams?
What would be the advantage of sending them at the same time?
- 12-02-2011, 04:07 PM #7
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Re: Are 2 Sockets Required?
The advantage is trying to achieve (or at least get closer to) better real time processing, especially in critical systems, where notifications from a server cannot wait for the client's request to be handled before being sent. Also the fact that your separating the streams, for catering requests (sending requested data) and sending requests (asking for required data), makes it easier for you (the programmer) to work with them.
- 12-02-2011, 06:00 PM #8
Re: Are 2 Sockets Required?
If your requirements are that a second response needs to be sent while the first one is being sent, then you would need another parallel connection to send it.
Would an example of that be when the server is returning a hugh file and then needs to tell the client something immediately in the midst of sending the hugh file and can not wait for the sending of the hugh file to complete?
If that is the case the client would need to have a ServerSocket that the "server" can connect to.
- 12-02-2011, 06:06 PM #9
Member
- Join Date
- Dec 2011
- Posts
- 19
- Rep Power
- 0
Re: Are 2 Sockets Required?
Yes Exactly! I am not sure, but you could design the server having two ServerSockets where the client connects to both of them, rather than having a ServerSocket within the client.
Thanks for your reply =)
- 12-02-2011, 06:24 PM #10
Similar Threads
-
Sockets
By Maya in forum NetworkingReplies: 6Last Post: 04-19-2011, 11:52 PM -
Sockets
By PhQ in forum New To JavaReplies: 1Last Post: 05-04-2010, 03:36 AM -
Sockets NIO
By aamp in forum New To JavaReplies: 3Last Post: 01-15-2009, 10:56 AM -
Sockets
By Zosden in forum NetworkingReplies: 16Last Post: 05-27-2008, 04:55 PM -
Help with Sockets
By Eric in forum NetworkingReplies: 3Last Post: 12-01-2007, 08:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks