Apr
10
Creating a Simple Chat Program 2 Direction TCP With C #
TCP is a protocol / rules of communication in a communication in computer networks. And the protocol type is the most widely used in building computer networks. What reason was?, Because this is the protocol that provides reliable facilities and security in data transmission. This protocol is often also called connection oriented, why?, Yes because it was an "oriented". The point?, Yes ... .. hehe confused Connection oriented means that in performing the data transmission (communication), before data can be transmitted between two hosts, two processes running on the application layer should negotiate to create session first. And in TCP is often referred to as the "Three-way handshake" or the cool term congratulation greetings ... .. hehe .... About the "Three-way handshake", before sending the data first host (who want to make a connection) will send a TCP segment with SYN flag (one of the TCP flags that indicate the corresponding TCP segment contains the Initial Sequence Number) is switched to the second host ( who would be invited to communicate). Then the second host will respond by sending a segment with ACK (TCP flags that indicate octet field contains the following acknowledgment to be expected in connection) and also to host the first SYN. After that, the first new host will begin exchanging data with the second host. If in everyday terms this process is like the word we want to visit the homes of people, then we should say hello, after greeting us was greeted then the landlord will let us in, only then we can chat with each other.
Okay just a brief explanation of TCP, go straight to the target, about making the program simple two-way chat with C #. Here's a little explanation discount program for client.
IPEndPoint ipep = new IPEndPoint (IPAddress.Parse("127.0.0.1"), 9050);
Socket server = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
Here the client makes IPEnd point, we first create a new variable called IPEnd point. The ditujuadalah servers, because we practiced in a computer then we just fill in the localhost address 127.0.0.1, if the two computers then input the address of the server computer. After going to make a socket or track, because it is the TCP socket used is Stream.
Then for the class server is a program like the following snippet.
IPEndPoint ipep = new IPEndPoint (IPAddress.Any, 9050);
Newsock socket = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
The server determines its IPEnd point is that all clients in a single incoming network address. recv = client.Receive (data);
Console.WriteLine (Encoding.ASCII.GetString (data, 0, recv));
Indicates the server program is ready to accept incoming connections.
For full source code i'm share in here.
Langganan:
Posting Komentar (Atom)
Posting Komentar