Click here to Skip to main content
15,886,689 members
Articles / Programming Languages / C#
Article

Network Stuff (easy socket v3)

Rate me:
Please Sign up or sign in to vote.
4.87/5 (52 votes)
2 Jun 2005 215.9K   6.1K   137   73
A class with event handlers for TCP, UDP or ICMP sockets; includes ping, traceroute, whois, ARP, and IPHelper functions and raw packets forging/ capturing.

Because of errors between VS 2002 and 2003, I've decided to put the two projects to solve resx and obsolete warning troubles.

Sample Image - networkstuff.jpg

Introduction

This code contains a class for socket: ICMP, TCP, UDP, raw TCP, raw UDP, raw IP, and a class for IPHelper functions. All the classes for socket are made with the same view: provide handler for events like connected, closed, closed_by_remote_side, data_arrival, error ....

The sample project is included in beta version, it provides a graphical interface for Telnet, ping, traceroute, whois, packet capture, packet forging, scanning, viewing stats (IPHelper sample), sending ARP, DNS, wake and shutdown on LAN.

How to use

See the following sample for TCP:

C#
easy_socket.tcp.Socket_Data clt;
clt=new easy_socket.tcp.Socket_Data();

// add events
clt.event_Socket_Data_Closed_by_Remote_Side+= new 
  easy_socket.tcp.Socket_Data_Closed_by_Remote_Side_EventHandler(
  socket_closed_by_remote_side);
clt.event_Socket_Data_Connected_To_Remote_Host +=new 
  easy_socket.tcp.Socket_Data_Connected_To_Remote_Host_EventHandler(
  socket_connected_to_remote_host);
clt.event_Socket_Data_DataArrival +=new 
  easy_socket.tcp.Socket_Data_DataArrival_EventHandler(socket_data_arrival);
clt.event_Socket_Data_Error+=new 
  easy_socket.tcp.Socket_Data_Error_EventHandler(socket_error);
  
// connect
clt.connect("127.0.0.1",80);

// handlers
protected void 
    socket_closed_by_remote_side(easy_socket.tcp.Socket_Data sender, 
    EventArgs e)
{

  // handler code
}

protected void 
    socket_connected_to_remote_host(easy_socket.tcp.Socket_Data sender, 
    EventArgs e)
{
  // handler code
}

protected void socket_data_arrival(easy_socket.tcp.Socket_Data sender, 
                         easy_socket.tcp.EventArgs_ReceiveDataSocket e)
{
    string strdata=System.Text.Encoding.Default.GetString(e.buffer, 
                                                0, e.buffer_size );
}

protected void socket_error(easy_socket.tcp.Socket_Data sender, 
                         easy_socket.tcp.EventArgs_Exception e)
{
    string strerror=e.exception.Message;
}

As you can see, you can save a lot of time using these classes.

History

  • 28 Feb 05 - updated VS.NET 2003 source code.
  • 09 May 05
    • Began Telnet protocol implementation.
    • Interactive TCP/UDP added.
    • Some bug corrections.
  • 03 Jun 05
    • Stat graphs added.
    • Interface improvement.
    • Telnet horizontal tab bug removed.
    • More bug corrections.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
France France

Comments and Discussions

 
GeneralRe: Capturing tcp Pin
rantanplanisback11-Oct-04 8:58
rantanplanisback11-Oct-04 8:58 
GeneralRe: Capturing tcp Pin
Daniel Grunwald11-Oct-04 9:32
Daniel Grunwald11-Oct-04 9:32 
GeneralRe: Capturing tcp Pin
rantanplanisback11-Oct-04 10:07
rantanplanisback11-Oct-04 10:07 
GeneralRe: Capturing tcp Pin
dfhgesart18-Feb-05 5:51
dfhgesart18-Feb-05 5:51 
GeneralRe: Capturing tcp Pin
icer139-Oct-05 4:52
icer139-Oct-05 4:52 
GeneralOther errors as well...... Pin
Keith Vinson6-Oct-04 8:14
Keith Vinson6-Oct-04 8:14 
GeneralRe: Other errors as well...... Pin
rantanplanisback6-Oct-04 9:02
rantanplanisback6-Oct-04 9:02 
GeneralRe: Other errors as well...... Pin
Keith Vinson6-Oct-04 9:35
Keith Vinson6-Oct-04 9:35 
VS 2003 DotNet 1.1 sp1.

Please don't take the following the wrong way, I look forward to seeing your project in action. But...


Ok maybe they are warnings except for the missing RESX file issue, but wouldn't it be better to not generate a bunch or warnings like:

D:\Downloads\DotNetCode\Network Stuff\networkstuff_src\tcp_header.cs(955): 'System.Net.IPAddress.Address' is obsolete: 'IPAddress.Address is address family dependant, use Equals method for comparison.'

You never know when an obsolete code warnings will turn fatal...

Or

D:\Downloads\DotNetCode\Network Stuff\networkstuff_src\icmp.cs(441): The keyword new is required on 'easy_socket.icmp.icmp_destination_unreachable.get_available_codes()' because it hides inherited member 'easy_socket.icmp.icmp.get_available_codes()'

I am not sure what the runtime will think about this. Does the code work as expected? After all it is warning about you hiding an inherited member, generally not a good thing.....

Maybe I am just old school, but experance has taught me that leaving warnings in a build only leads to trouble.

A) sometimes the complier is right and it is a problem that leads to incorrect results which are hard to find.

B) Having a bunch of warnings that are "suppose" to be there has a tendency to hide warnings that are not suppose to be there. see reason A.

To me its like leaving another a round in the chamber. If you let your pet monkey play with your loaded gun its only a matter of time before you get shot.....

Keith
GeneralRe: Other errors as well...... Pin
rantanplanisback7-Oct-04 6:18
rantanplanisback7-Oct-04 6:18 
GeneralRe: Other errors as well...... Pin
Keith Vinson7-Oct-04 6:24
Keith Vinson7-Oct-04 6:24 
GeneralError! Pin
Shahrokh Shirzad5-Oct-04 20:53
Shahrokh Shirzad5-Oct-04 20:53 
GeneralRe: Error! Pin
rantanplanisback6-Oct-04 9:18
rantanplanisback6-Oct-04 9:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.