When server send data then client receive that data, in C# windows services where data receive continuously (Using IP Address and port number) . Please any one have idea help me code. Thanks one and all. This below code writing in console application . i want implement same logic in windows service side. but i want data receive continuously.
Above code write in console application, same logic implementing in windows service, but i want data receiving continuously
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using System.IO; namespace ClientApplication { class Client { public static void Main() { IPEndPoint ip = new IPEndPoint(IPAddress.Parse("192.168.1.202"), 9000); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { server.Connect(ip); } catch (SocketException e) { Console.WriteLine("Unable to connect to server." +e); return; } byte[] data = new byte[1024]; int receivedDataLength = server.Receive(data); string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); Console.WriteLine(stringData); server.Shutdown(SocketShutdown.Both); server.Close(); } } }
Comment