Brother wrote a socket connected to a computer program, but found to not get fat, but I wrote a server program, the client will be able to receive it? ? Is that why it? ? ?
I think the program is estimated no problem
Client: pitch-catch. . . . PC network debugging assistant hair received, but the client will block read that
public class Main extends Activity
{
public void onClick_Data_Transmit (View view)
{
try
{
Socket socket = new Socket ("114.250.22.85", 7002);
OutputStream os = socket.getOutputStream ();
OutputStreamWriter osw = new OutputStreamWriter (os);
BufferedWriter bw = new BufferedWriter (osw);
bw.write ("111111111111");
bw.flush ();
InputStream is = socket.getInputStream ();
InputStreamReader isr = new InputStreamReader (is);
BufferedReader br = new BufferedReader (isr);
String s = "";
TextView textView = (TextView) findViewById (R.id.textview);
s = br.readLine ();
/ / While ((s = br.readLine ())! = Null)
textView.append (s + "\ n");
socket.close ();
}
catch (Exception e)
{
/ / TODO: handle exception
}
}
}
I wrote a server:
class SimpleServer
{
public static void main (String [args)
throws IOException
{
/ / Create a ServerSocket, Socket to listen for client connection requests
ServerSocket ss = new ServerSocket (7002);
/ / Use cycle continuously receiving requests from the client
while (true)
{
/ / Whenever Socket client receives the request, the server also generates a corresponding Socket
Socket s = ss.accept ();
OutputStream os = s.getOutputStream ();
os.write ("Hello, you receive the server's New Year greeting!"
. GetBytes ("utf-8"));
/ / Close the output stream, close Socket
os.close ();
s.close ();
}
}
}
Some people say to add the / r / n in the data sent, I added, or wood with ah ~ ~ ~
Reply:
I found the network debugging assistant disconnected. . . Client actually received the code. . . . However, / r / n or the like as a character string to be completely received. . . .
Reply:
In hexadecimal display with 0D 0A
Reply:
Sure enough so
Reply:
Thank you thank you, bothering me one day, I really do not know how to thank you
Reply:
I would like to ask, why do so you can communicate it
Reply:
Indicates the end
No comments:
Post a Comment