User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 402,732 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,479 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1613 | Replies: 6
Reply
Join Date: Jul 2007
Posts: 14
Reputation: bumassjp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bumassjp's Avatar
bumassjp bumassjp is offline Offline
Newbie Poster

Need to create a Threaded IP Listener, where to start?

  #1  
Aug 15th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 311
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Need to create a Threaded IP Listener, where to start?

  #2  
Aug 16th, 2007
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.
Last edited by iamthwee : Aug 16th, 2007 at 2:27 pm.
Reply With Quote  
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 279
Reputation: JerryShaw is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
JerryShaw JerryShaw is offline Offline
Posting Whiz in Training

Re: Need to create a Threaded IP Listener, where to start?

  #3  
Aug 17th, 2007
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.
Reply With Quote  
Join Date: Jul 2007
Posts: 14
Reputation: bumassjp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bumassjp's Avatar
bumassjp bumassjp is offline Offline
Newbie Poster

Re: Need to create a Threaded IP Listener, where to start?

  #4  
Aug 22nd, 2007
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?
Reply With Quote  
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 279
Reputation: JerryShaw is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
JerryShaw JerryShaw is offline Offline
Posting Whiz in Training

Re: Need to create a Threaded IP Listener, where to start?

  #5  
Aug 22nd, 2007
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.
Example:
Socket sock = new Socket(AddressFamily.Internetwork, SocketType.Dgram, ProtocolType.Udp);

J
Reply With Quote  
Join Date: Jul 2007
Posts: 14
Reputation: bumassjp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bumassjp's Avatar
bumassjp bumassjp is offline Offline
Newbie Poster

Re: Need to create a Threaded IP Listener, where to start?

  #6  
Sep 5th, 2007
  
  1.  
  2. using System;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using System.Text;
  6.  
  7. public class SimpleUdpClient
  8. {
  9. public static void Main()
  10. {
  11. byte[] data = new byte[1024];
  12. string input, stringData;
  13. IPEndPoint ipep = new IPEndPoint(
  14. IPAddress.Parse("127.0.0.1"), 9050);
  15.  
  16. Socket server = new Socket(AddressFamily.InterNetwork,
  17. SocketType.Dgram, ProtocolType.Udp);
  18.  
  19.  
  20. string welcome = "Hello, are you there?";
  21. data = Encoding.ASCII.GetBytes(welcome);
  22. server.SendTo(data, data.Length, SocketFlags.None, ipep);
  23.  
  24. IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
  25. EndPoint Remote = (EndPoint)sender;
  26.  
  27. data = new byte[1024];
  28. int recv = server.ReceiveFrom(data, ref Remote);
  29.  
  30. Console.WriteLine("Message received from {0}:", Remote.ToString());
  31. Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  32.  
  33. while(true)
  34. {
  35. input = Console.ReadLine();
  36. if (input == "exit")
  37. break;
  38. server.SendTo(Encoding.ASCII.GetBytes(input), Remote);
  39. data = new byte[1024];
  40. recv = server.ReceiveFrom(data, ref Remote);
  41. stringData = Encoding.ASCII.GetString(data, 0, recv);
  42. Console.WriteLine(stringData);
  43. }
  44. Console.WriteLine("Stopping client");
  45. server.Close();
  46. }
  47. }



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?
Reply With Quote  
Join Date: Jul 2007
Posts: 14
Reputation: bumassjp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bumassjp's Avatar
bumassjp bumassjp is offline Offline
Newbie Poster

Re: Need to create a Threaded IP Listener, where to start?

  #7  
Sep 5th, 2007
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?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 7:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC