Today wrote a simple program, this machine and the server through the socket communication, this machine send native IP to the server, and then the server returned information to the machine, but the machine has not received, if the server that the program closed, this side can receive, really dizzy. Don't know what's going on.
Feel that your code should be fine, but Liang said he should have no problem there. Later sent a post to consult, said may be VB there is no add line break or no flush and so on, and then let Liang that the VB program plus line break, testing, hehe, really received.
The native code is as follows:
public class PC {public static void main (string[] args) {String remote = ' 192.168.1.5 '; try {//Get native IP inetaddre SS addr = Inetaddress.getlocalhost (); String Localhostip = addr.gethostaddress (); Socket socket = new socket (remote,1011); Send native IP to remote host outputstream OS = Socket.getoutputstream (); BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (OS)); Bw.write (Localhostip); Bw.flush (); Accept the instruction sent by the host inputstream is = Socket.getinputstream (); BufferedReader br = new BufferedReader (new InputStreamReader (IS)); String line = null; while ((Line=br.readline ())!= null) {SYSTEM.OUT.PRINTLN ("the message Received is:" +line);/** * Below start the relevant steps according to the IR number, if the projector is playing the content, When the next IR trigger causes the projector to replay, a delay should be set. *//If VB send the message of the code does not add line breaks, then this side can still be obtained, the following methods//byte[] buf = new byte[1024]; Is.read (BUF); String msg = new String (buf, "gb2312"); Br.close (); Is.close (); Bw.close (); Os.close (); Socket.close (); catch (Exception e) {System.out.println ("main exception:" +e.getmessage ());} }