kvarnerexpress 0 Report post Posted July 11, 2005 How do sockets work in java? I have only previously been exposed to the VB winsock control, which receives data automatically as an event. From a tutorial i've seen, it looks like all incoming data has to be manually read using a bufferedreader, perhaps using a continuous loop, is that how it goes?kvarnerexpress Share this post Link to post Share on other sites
cse-icons 0 Report post Posted July 12, 2005 hi kvarnerexpress,In Java one application runs the ServerSocket on a particular port and waits for clients to connect to it.The clients establish a connection with the server socket using Socket object with ip address and port as parameter. After this connection is established, two streams(an input and an output) are available for the connection(some method like sc.getInputStream() /sc.getOutputStream()... where sc is the socket object) These streams are then used for connection communication by writing to the output stream and reading from the input stream. These can be wrapped over with a Reader/BufferedReader or Writer/BufferedWriter class.The reading part is not event triggered but process controlled i.e, you need to read explicitly when you are expecting something on the connection... A way out is to start a separate thread which would maintain the connection and continuously read from the stream. When it gets something on the stream it would set a static variable which can be used as a flag variable to poll once in a while and determine if the event has occurred.I have written this with an idea that you have more than basic idea of Java and a little knowledge of network communication. If I have not been clear in any part, do post your question...You can even find sample Client/Server program on the net. Execute both on your system and put in debug statements all over to get the idea of the flow of control.. Play around and you will learn a lot more...Cheers. Share this post Link to post Share on other sites