I use a button's click event to create a socket in the interface, as follows:
sock = new Socket (tv_ip.getText () toString (), port.);
in = new BufferedReader (new InputStreamReader (sock.getInputStream ()));
out = new PrintWriter (new BufferedWriter (new OutputStreamWriter (sock.getOutputStream ())), true);
In addition, I use another button to send the data, as follows:
if (sock.isConnected ()) {
if (! sock.isOutputShutdown ()) {
out.println (str_send);
tv_result.setText (str_send);
}
}
But only made once, you must click a button to create a socket, you can send it again. Logically, I did not close the socket connection. Because of the android socket handling mechanism is not very familiar with, but also please advise seniors advise, how to maintain socket created until the program ends
Reply:
Reply:
no one? Their top a
Reply:
socket I did not how used, I do not know ah
Reply:
Is not it, I feel for you seniors, it should be a very simple question ah!
Reply:
while loop wrapped
Reply:
Does not it? How you control
Reply:
But only made once, you must click a button to create a socket, you can send it again. Logically, I did not close the socket connection. Because of the android socket handling mechanism is not very familiar with, but also please advise seniors advise, how to maintain socket created until the program ends
socket get the input and output streams, and the corresponding flow can not be shut down, closed the lead to socket failure, need to re-initialize, especially when ssl connection, the effect will be particularly poor. write out call outsteam.flush () after the stream on the line, do not close
Reply:
Calling flush not ah. The whole process, I do not have the corresponding stream Close
Reply:
It is a service to shut down the bar
Reply:
No ah. Here is the code
services
while (1)
{
SOCKET sockcln = accept (sockSrv, (sockaddr *) & amp; addrClient, & amp; len);
unsigned long IP = addrClient.sin_addr.S_un.S_addr;
printf ("get connect request from IP:% d% d% d% d \ n...", (IP & lt; & lt; 24) & gt; & gt; 24, (IP & lt; & lt; 16) & gt; & gt; 24, (IP & lt; & lt; 8) & gt; & gt; 24, IP & gt; & gt; 24);
char recvBuf [100];
memset (recvBuf, 0, sizeof (recvBuf));
recv (sockcln, recvBuf, sizeof (recvBuf), 0);
parseMsg (recvBuf);
}
Reply:
Great God seeking guidance ah!
Reply:
Should use the while loop package, set up a judge, after the data has been received, emptied it
Reply:
Certainly where there is the anomaly

Reply:
Reply:
No comments:
Post a Comment