java - Send data to an open server socket -
i have socket server program running on remote machine,i want send data through client socket program without creating new socket connection everytime. long server socket open need send data.need java code same. code im using works fine first time.second time run it,it says connection refused.
string host = "machinename"; int port = 23000; inetaddress address = inetaddress.getbyname(host); //establish socket connection server socket = new socket(address, port); //send msg server outputstream os = socket.getoutputstream(); outputstreamwriter osw = new outputstreamwriter(os); bufferedwriter bw = new bufferedwriter(osw); string request = "data"; string sendmessage = request + "\n"; bw.write(sendmessage); bw.flush(); inputstream = socket.getinputstream(); inputstreamreader isr = new inputstreamreader(is); bufferedreader br = new bufferedreader(isr); string message = br.readline();
second time run it,it says connection refused.
that can mean server, code haven't posted here, has closed listening socket after processing 1 client.
Comments
Post a Comment