发送TCP数据的Android(如客户端) - 发送任何数据? [英] Sending TCP data from Android (as client) - no data being sent?
问题描述
我想从我的Android应用程序将数据发送到我的电脑通过TCP。
I'm trying to send data from my Android app to my PC over TCP.
在code是如下:
Socket socket = new Socket("10.0.78.75", 50505);
OutputStream out = socket.getOutputStream();
PrintWriter output = new PrintWriter(out);
mStatusText.setText("Sending Data to PC");
output.println("Hello from Android");
mStatusText.setText("Data sent to PC");
socket.close();
mStatusText.setText("Socket closed");
我没有得到任何错误可言,而这样做,但是,服务器应用程序(C#编写的),没有得到任何数据。 它把客户端连接到它,并看到正在发送数据,但是数据串出来的空...而上为什么会这样的想法?
I don't get any errors at all while doing this, however, the server application (written in C#) does not get any data. It sees the client connect to it, and sees that data is being sent, however, the data string comes out empty... And thoughts on why this is happening?
PS:服务器code从以下站点复制并已经过测试,与C#TCP客户端。 <一href="http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-simple-threaded-tcp-server">http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-simple-threaded-tcp-server
PS: The server code is copied from the following site and has been tested with a C# TCP client. http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server
推荐答案
尝试把一个了out.flush(); out.close();在<$ C
之后$ C>的println(..);
Try putting an out.flush();out.close();
after the println(..)
;
这篇关于发送TCP数据的Android(如客户端) - 发送任何数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!