Can anyone give me a place to read up on these or possibly an outline of one? I need to register an IP and then collect data from the device.

9 Years
Discussion Span
Last Post by bumassjp

I'd look up the ms commands for windows. Such as ping, nbtstat, etc.

You could call them as process. However, there also happens to be inbuilt IP functions in the dotnet framework, although I've never used them.


Do a Google search on c# Server Socket, and/or get the book "TCP/IP Sockets in C#" by David B Makofske, Michael Donahoo and Kenneth Calvert. This book goes into threading the server and client with lots of examples.


Thanks for the good advice. I think that book will be a big help in trying to figure this crap out.... another question, I think the listener might have to be udp. would that be essentially the same thing except using a different function in .net?


Selecting the UDP protocol is very similar to selecting Tcp, Echo, Ftp, etc etc. You will find plenty of examples of using UDP in the book.

Socket sock = new Socket(AddressFamily.Internetwork, SocketType.Dgram, ProtocolType.Udp);


using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class SimpleUdpClient
   public static void Main()
      byte[] data = new byte[1024];
      string input, stringData;
      IPEndPoint ipep = new IPEndPoint(
                      IPAddress.Parse(""), 9050);

      Socket server = new Socket(AddressFamily.InterNetwork,
                     SocketType.Dgram, ProtocolType.Udp);

      string welcome = "Hello, are you there?";
      data = Encoding.ASCII.GetBytes(welcome);
      server.SendTo(data, data.Length, SocketFlags.None, ipep);

      IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
      EndPoint Remote = (EndPoint)sender;

      data = new byte[1024];
      int recv = server.ReceiveFrom(data, ref Remote);

      Console.WriteLine("Message received from {0}:", Remote.ToString());
      Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));

         input = Console.ReadLine();
         if (input == "exit")
         server.SendTo(Encoding.ASCII.GetBytes(input), Remote);
         data = new byte[1024];
         recv = server.ReceiveFrom(data, ref Remote);
         stringData = Encoding.ASCII.GetString(data, 0, recv);
      Console.WriteLine("Stopping client");

my main question is in line 13-14 does that line tell the device what IP to listen for or is that what IP to listen on?

Edited by __avd: fixed formatting.


ok I think i may have answered my own question... My next question is, is there a function I can replace line 13-14 with to make the program listen blindly for anything on the open port?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.