iam beginner in socket programming
i made a simple server and client programs to send an receive a string from (the string sent from server to client)
The server code :
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 100);
socket.Bind(iep);
socket.Listen(4);
socket.Accept();
Console.WriteLine("we get the connection");
string s = "samer";
byte[] buffer = Encoding.ASCII.GetBytes(s);
socket.Send(buffer);
The client code :
private void button1_Click(object sender, RoutedEventArgs e)
{
Socket client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//IPEndPoint iep = new IPEndPoint(IPAddress.Any, 100);
//client_socket.Bind(iep);
client_socket.Connect(textBox1.Text, 100);
byte[] buffer=new byte[1024];
client_socket.Receive(buffer);
textBox2.Text = Encoding.ASCII.GetString(buffer);
}
The problem appends in server program in (socket.send(buffer)) the compiler said that :
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
so what the problem exactly ??

New Topic/Question
Reply




MultiQuote





|