C# (クライアント) と Python (サーバー) 間の基本的なソケット通信に取り組んでいますが、クライアントからこのエラーが発生する理由がわかりません。
[エラー] 致命的な未処理の例外: System.Net.Sockets.SocketException: System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00159] で接続が/private/tmp/monobuild/build/BUILD/ で拒否されましたmono-2.10.9/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1262 at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in /private/tmp/ monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net.Sockets/TcpClient.cs:284 at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x000b3] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net.Sockets/TcpClient.cs:355
私のプログラムは本当に短くて簡単なので、初心者の質問だと思いますが、わかりません。私が欲しいのは、クライアントがサーバーにメッセージを送信して、それをコンソールに出力することだけです。
これが C# クライアントです (エラーは :socket.Connect("localhost",9999); から発生します)。
using System;
using System.Net.Sockets;
namespace MyClient
{
class Client_Socket{
public void Publish(){
TcpClient socket = new TcpClient();
socket.Connect("localhost",9999);
NetworkStream network = socket.GetStream();
System.IO.StreamWriter streamWriter= new System.IO.StreamWriter(network);
streamWriter.WriteLine("MESSAGER HARGONIEN");
streamWriter.Flush();
network.Close();
}
}
}
そして Python サーバー:
from socket import *
if __name__ == "__main__":
while(1):
PySocket = socket (AF_INET,SOCK_DGRAM)
PySocket.bind (('localhost',9999))
Donnee, Client = PySocket.recvfrom (1024)
print(Donnee)
ありがとうございます。