Another question i've created Windows Form Application which is Server but the problem is that when i create this code the Application Freezes and when i click on it ..it gives me Not Responding Error ..Same for client ... it connects to the server then Freeze and give me same Not Responding Error
Problem ScreenShot
Here Are the Codes I used
used Ip = "127.0.0.1", Port = 5100
Code:
public void StartServer(string Ip, ushort Port)
{
Soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Soc.Bind(new IPEndPoint(IPAddress.Parse(Ip), Port));
textBox2.Text += " Server Is Created On Ip : " + IpAdd + ", Port : " + Port + Environment.NewLine;
Soc.Listen(100);
textBox2.Text += " Server Is Listening to Clients Now... " + Environment.NewLine;
StartListening();
}
Code:
public void StartListening()
{
while (true)
{
var Client = Soc.Accept();
textBox2.Text += " Client Located At Ip : " + Client.RemoteEndPoint + " Is Now Connected To Server " + Environment.NewLine;
byte[] ReceivedBytes = new byte[1024];
int ReceivedDataLength = 0;
while ((ReceivedDataLength = Soc.Receive(ReceivedBytes)) > 0)
{
string MessageFromClient = ASCIIEncoding.ASCII.GetString(ReceivedBytes, 0, ReceivedBytes.Length);
textBox2.Text += " Message Sent to Server : " + MessageFromClient + Environment.NewLine;
}
}
}
regards
shadowman123







