Answer the question
In order to leave comments, you need to log in
How to setup C# sockets?
Hello! Such a problem has arisen. It is necessary that the client and the server communicate with each other, i.e. The client could listen and send data, and the server had the same characteristics.
Here is the server
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public void getText ()
{
socket.Bind(new IPEndPoint(IPAddress.Any, 80));
socket.Listen(1000000);
Socket client = socket.Accept();
byte[] buffer = new byte[1024];
client.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer));
Console.ReadKey();
}
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public void connect()
{
socket.Connect("127.0.0.1", 80);
}
public void GiveOnline (string message)
{
connect();
byte[] buffer = Encoding.ASCII.GetBytes(message);
socket.Send(buffer);
socket.Bind(new IPEndPoint(IPAddress.Any, 8080));
socket.Listen(1);
socket.Accept();
socket.Receive(buffer);
}
Answer the question
In order to leave comments, you need to log in
https://stackoverflow.com/questions/1777629/how-to...
> You cannot bind a single socket to multiple endpoints. A SocketException (invalid argument error) occurs the second time you call Bind() for a given socket.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question