誰かが私を助けてくれますか? 私はlistener.startに達した場合にエラーが発生します しかし、私は開いているTCP接続がありません。 エラー: は{「通常、各ソケットアドレス(プロトコル、ネットワークアドレス、またはポート)が一度だけ使用される」}C#listener.startに到達した場合のTCPクライアントエラー
スタックトレース= "System.Net.Sockets.Socket.DoBindに(エンドポイントendPointSnapshot、のSocketAddressソケットアドレス) System.Net.Sockets.Socket.Bind(EndPointローカルEP)の\ r \ n System.Net.Sockets.TcpListener.Start(Int32バックログ)\ r \ n(System.Net.Sockets.TcpListene)\ r \ n 。
const int PORT_NO = 3242;
const string SERVER_IP = "127.0.0.1";
public static void send()
{
IPAddress localAdd = IPAddress.Parse(SERVER_IP);
TcpListener listener = new TcpListener(localAdd, PORT_NO);
try
{
StreamReader sr = new StreamReader(Application.StartupPath + Info.MainFile);
string text = sr.ReadToEnd();
sr.Close();
//Hier den string rein geben !
byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(text);
Console.WriteLine("Listening...");
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream nwStream = client.GetStream();
byte[] buffer = new byte[client.ReceiveBufferSize];
//int bytesRead = nwStream.Read(buffer, 0, client.ReceiveBufferSize);
int bytesRead = nwStream.Read(buffer, 0, client.ReceiveBufferSize);
string dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead);
Console.WriteLine("Received : " + dataReceived);
Console.WriteLine("Sending back : " + dataReceived);
//nwStream.Write(buffer, 0, bytesRead);
nwStream.Write(bytesToSend, 0, bytesToSend.Count());
//client.Close();
listener.Stop();
Console.ReadLine();
}
catch(Exception ex)
{
//StreamWriter sw = new StreamWriter(Application.StartupPath + Info.Log, true);
//sw.WriteLine(ex.InnerException);
//sw.Flush();
//sw.Close();
listener.Stop();
}
}
完全なエラーメッセージは何ですか? – Brian
Stack Trace = "System.Net.Sockets.Socket.DoBind(エンドポイントendPointSnapshot、SocketAddressソケットアドレス)\ r \ n System.Net.Sockets.Socket.Bind(EndPoint localEP)\ r \ n System.Netにあります。 Sockets.TcpListener .Start(Int32バックログ)\ r \ n System.Net.Sockets.TcpListene ... –
あなたの質問にそれを編集することができます。コメントにコードを入れることは実際にはうまくいきません:\ – Brian