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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -