This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Question about "socket"

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic