Using multiple clients together is a simple public chat room. Server for a console program using C # Implementation, of course, in the Unity3d also use the C # language to implement the client, server and client can realize the exchange of messages, when the server received a message sent by a client will be the client List members broadcast, This is the most basic form of a public chat room. Socket communication is the most basic knowledge of online games, so this example can provide guiding significance for beginners who are interested in the online game industry.
 
Using System;  
Using System.Collections.Generic;  
Using System.Linq;  
Using System.Text;  
Using System.Net.Sockets;  
Namespace TestServer  
{  
class program  
{  
//Set connection port  
const int PORTNO =;  
static void Main (string[] args)  
{  
//Initialize server IP  
System.Net.IPAddress localadd = System.Net.IPAddress.Parse ("127.0.0.1");  
Create a TCP listener  
tcplistener listener = new TcpListener (Localadd, portno);  
Listener. Start ();  
Displays server startup information  
Console.WriteLine ("Server is starting...\n");  
Loops accept the client's connection request while  
(true)  
{  
chatclient user = new ChatClient (listener). AcceptTcpClient ());  
Displays the IP and Port  
Console.WriteLine (User._clientip + "is joined...\n") of the Connection Client;}}}  
 
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/