• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about "socket"

 
Daniel Washington
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanna create a client-server application and need to transfer various kinds of information between C-S, these information includes identity validation , talking and some others : And my question is : Can i declare numbers of input streams and output streams in a single socket connection just like "new data input stream(socket.getinput stream() )"? If yes , How can i do that ?If no, Does that mean i should creat numbers of input(output)streams for each kinds of information using numbers of socket connection ? I am looking forward to receiving your earliest reply . Thanks !
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not crosspost the same topic in multiple forums.
I'm moving this thread to the Sockets and Internet Protocols forum. Please continue this discussion there.
This topic is now closed. Thank you
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is no.
Besides, why would you want to have differnt streams for different information.
Just send it all down the same socket, and label the message so that the server can find out the type of message sent.
for example:
CLIENT sends the following message to server requesting to logon:
/logon: <username> <password>

---------------------------------------------------------------------------

SERVER PROCESS
msgType = inMsg.substring(0,<index of :> ;
if(msgType.equals(Messages.LOGON))
// store IP, check username and pw against a db.
else if(msgType.equals(Messages.LOGOFF))
// log the user off, i.e. remove there IP address from some static list

Hope this helps.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James' reply suggests that, with a bit of work, you could have multiple input and output streams working through a single socket -- but you'd have to write a multiplexer and demultiplexer yourself, as well as the custom stream types. Basically you'd do what James describes, but implement the InputStream and OutputStream protocols in doing so. Not for the faint of heart!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!