well i've Gone through socket and understood lots of things ..i got questions about it .. i've read that Async Sockets are better than Sync socket cuz Sync sockets Blocks the main Thread unlike the Async so the question is .. since Async is better than Sync socket why they have created it since every1 would use the better socket Type which is Async ... in other Rephrase when should i use Sync sockets ? .. and i'd like to know about Cons and Pros of using TcpListeners and TcpClient instead of Mentioned Socket Types above ...
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
Additional Question : How can i remove that Stupid Shadow surrounding the Application Border ? its makes the Application look worse , shitty
regards
shadowman123
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