0
Here’s the part of the code that misses:
private void buttonAbrirConexão_Click(object sender, EventArgs e)
{
try
{
socketOfServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketOfServer.Bind(new IPEndPoint(IPAddress.Any, 6554));
socketOfServer.Listen(100);
socketOfServer.BeginAccept(AcceptedConection_Callback, null);
MessageBox.Show("Servidor aberto!");
buttonAbrirConexão.Enabled = false;
}
catch(Exception ex)
{
buttonAbrirConexão.Enabled = true;
MessageBox.Show(ex.Message);
}
}
private void AcceptedConection_Callback(IAsyncResult e)
{
socketOfClientOnServer = socketOfServer.EndAccept(e);
socketOfServer.BeginReceive(bufferOfServer, 0, bufferOfServer.Length, SocketFlags.None, AcceptedDataFromClient_Callback, socketOfClientOnServer); //O erro da nessa linha
MessageBox.Show("Cliente conectado!");
}
First of all I follow the following steps, click on open server, a message appears saying that the server opened, then I click on connect using ip 127.0.0.1, if I remove the line that is giving error, displays me a message saying that the client is connected. The mistake you’re making on the line is this::
"A request for sending or receiving data was not allowed because the socket is not connected and (during sending on a datagram socket using a sendto call) an address was not provided." Note: I connect only one customer.
I know nothing of . Net but the line that gives error
socketOfServer.BeginReceive(bufferOfServer,...
should start withsocketOfClientOnServer.BeginReceive(...
, because "socketOfServer" is the Listener, and "socketOfClientOnServer" is the connected socket... about the other parameters do not know enough to say something– zentrunix
Dude, you are at least a demigod... IT WAS JUST THAT!!!! AAAAAAAA The problem is my lack of knowledge about socket, so I’ve been doing things hopelessly :/
– Ícaro Dantas