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 !
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
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
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!