我在服务器端创建了一个php程序
$host = "my server ip";
$port = port;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
echo "Client Message : ".$input;
socket_write($spawn, $input, strlen ($input)) or die("Could not write output\n");
socket_close($spawn);
socket_close($socket);
并创建一个c#winform程序:
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
clientSocket.Connect("185.8.175.44", 8081);
NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes("i am ready");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
byte[] inStream = new byte[512 * 512 * 512];
serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
richTextBox1.Text = Convert.ToString(returndata) + "\n";
我的问题是我无法将数据从服务器发送到桌面程序。 启动程序时,我收到的是我发送的任何内容,但是连接后,我没有将数据从服务器发送到桌面。