using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Test___server { class server { public static string serverIP = "192.168.0.102"; static void Main(string[] args) { Thread listenSendingThread = new Thread(listenSending); listenSendingThread.IsBackground = true; listenSendingThread.Start(); Thread listenReceivingThread = new Thread(listenReceiving); listenReceivingThread.IsBackground = true; listenReceivingThread.Start(); Console.ReadKey(); } public static List<TcpClient> listSending = new List<TcpClient>(); public static List<TcpClient> listReceiving = new List<TcpClient>(); public static TcpClient clientSending = null; private static void listenSending() { TcpListener listenerSending = new TcpListener(IPAddress.Parse(serverIP), 5319); listenerSending.Start(); Console.WriteLine("Server listening to " + serverIP + ":5319"); while(true) { clientSending = listenerSending.AcceptTcpClient(); listSending.Add(clientSending); Console.WriteLine("Sender connection received from " + clientSending.Client.RemoteEndPoint); } } private static void send() { StreamWriter sw = new StreamWriter(clientSending.GetStream()); sw.WriteLine(message); sw.Flush(); Console.WriteLine("Message sent!"); } public static string message = string.Empty; private static void listenReceiving() { TcpListener listener = new TcpListener(IPAddress.Parse(serverIP), 0045); listener.Start(); Console.WriteLine("Server listening to " + serverIP + ":0045"); while (true) { TcpClient client = listener.AcceptTcpClient(); listReceiving.Add(client); Console.WriteLine("Receiver connection received from " + client.Client.RemoteEndPoint); StreamReader sr = new StreamReader(client.GetStream()); message = sr.ReadLine(); send(); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Test____admin { class admin { static void Main(string[] args) { Console.WriteLine("Begin"); string serverIP = "192.168.0.102"; System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient(); clientSocket.Connect(serverIP, ); Console.WriteLine("Connected"); while (true) { Console.WriteLine("Reading"); StreamReader sr = new StreamReader(clientSocket.GetStream()); Console.WriteLine("Message: " + sr.ReadLine()); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; namespace Test___client { class client { public static string serverIP = "192.168.0.102"; static void Main(string[] args) { clientConnect(); } private static void clientConnect() { try { TcpClient client = new TcpClient(serverIP, 0045); StreamWriter sw = new StreamWriter(client.GetStream()); sw.WriteLine("Karan!"); sw.Flush(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)