我对套接字编程颇为陌生,但这里什么都不做。PHP客户端和C#服务器 - 由于超时而无法通信
我一直在尝试在C#服务器和PHP客户端之间进行一些简单的TCP通信。但是,我没有在他们之间建立联系的运气。我基本上是通过PHP套接字通信通过Web浏览器发送桌面应用程序消息。但是,我不断收到超时错误。
我的代码如下:
我的C#服务器代码 - 它只是简单地聆听,并通知我,如果建立了连接
static void Main(string[] args)
{
try
{
IPAddress localAddress = IPAddress.Parse("xx.xx.xx.xx");
TcpListener listener = new TcpListener(localAddress, 4761);
listener.Start(1);
while (true)
{
Console.WriteLine("Server is waiting on socket {0}", listener.LocalEndpoint);
TcpClient client = listener.AcceptTcpClient();
NetworkStream IO = client.GetStream();
Console.WriteLine("Recieved a connection from {0}", client.Client.RemoteEndPoint);
Console.WriteLine("Time to depart.");
client.Close();
}
}
catch (Exception E)
{
Console.WriteLine("Caught exception: {0}", E.ToString());
}
}
PHP客户端 - 这是我提出的一项功能只是连接到服务器(失败悲惨)
public function Hook_Up($Host_IP)
{
$this->String_and_Cup = fsockopen("xx.xx.xx.xx", 4761);
if($this->String_and_Cup)
{
echo "Congratulations, it's a socket connection...";
}
else
{
echo "I'm sorry, the socket connection didn't make it...";
}
}
所有我想要这么做是通过浏览器连接到这个服务器。我很感激关于如何这样做的意见。
在此先感谢。
哇,谢谢你的链接和建议!我真的很感激!我会继续在早上检查一下,并告诉你它是如何工作的。再次感谢你! – Exitium