Click here to Skip to main content
15,891,136 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 216.5K   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: GPL... Pin
IGx8929-Mar-05 10:28
IGx8929-Mar-05 10:28 
GeneralRe: GPL... Pin
pedrito6810-May-05 5:35
pedrito6810-May-05 5:35 
GeneralRe: GPL... Pin
Robert M. Bouwens9-May-05 19:58
Robert M. Bouwens9-May-05 19:58 
GeneralRe: GPL... Pin
Sean McCormack3-Jun-05 6:14
Sean McCormack3-Jun-05 6:14 
GeneralRe: GPL... [modified] Pin
Ryan L. Schneider24-Jul-06 5:33
Ryan L. Schneider24-Jul-06 5:33 
GeneralTCP SYN SYN/ACK issues Pin
banduraj15-Mar-05 8:56
banduraj15-Mar-05 8:56 
GeneralRe: TCP SYN SYN/ACK issues Pin
rantanplanisback22-Mar-05 11:24
rantanplanisback22-Mar-05 11:24 
GeneralSource code formatting Suggestion Pin
Mark Belles27-Feb-05 18:17
Mark Belles27-Feb-05 18:17 
I have not taken a walk through this latest update of your source code, simply for the fact that it appears that you have decided to break every formatting rule of .NET coding standards.

How, you are able to continue coding in the older C style, is well beyond me. I really feel strongly about how difficult it is to read code that doesn't adhere to either Camel or Pascal casing.

Camel casing is quite popular among Java developers, where the method names are always first word lower, subsequent words being proper cased.

Camel casing sample...
startUsingCamelCasing(bool goodIdeaOrNot);

Where as Pascal casing proper cases all words in method and property names. Pascal casing is found throughout the .NET BCL (base class libraries), and imho IS much easier to read than all other coding standards.

Pascal casing sample...
PleaseUsePascalCasing(bool betterIdeaAccordingToMe);

To provide reasons besides shear bias, for my arguments. With older C style coding, where everything is lower cased, and underscores are used to separate words in methods or types, it's nearly impossible to discern the different between a variable, method, or a type! At least in Camel or Pascal casing the Type's are proper cased so that it's easy to identify classes and structs quickly over variables.

Not to mention some sort of scoping standards, like using m_ or _ to prefix class scoped variables. Large projects, and complicated code are bad enough without making everyone guess as to the scope of a variable, or even whether it's a variable and not a type or method!

If you would change your formatting to more closely follow either of these coding standards, I believe you would receive better feedback from your viewers. Many may be like me, and see strange formatting and simply walk away.

Please consider my suggestions, I in no way consider you a bad programmer because of your formatting, but you should adapt to standards that are popular to help your viewers and fellow programmers.



Only those who attempt the absurd, can achieve the impossible.
GeneralRe: Source code formatting Suggestion Pin
Mark Belles27-Feb-05 18:31
Mark Belles27-Feb-05 18:31 
GeneralRe: Source code formatting Suggestion Pin
jacquelin.potier3-Mar-05 10:32
sussjacquelin.potier3-Mar-05 10:32 
GeneralRe: Source code formatting Suggestion Pin
Huisheng Chen9-May-05 18:41
Huisheng Chen9-May-05 18:41 
GeneralGot 1 errors, 3 Warning Pin
anonymous....29-Jan-05 3:40
sussanonymous....29-Jan-05 3:40 
GeneralRuntime Exceptions Pin
dfhgesart29-Jan-05 3:55
dfhgesart29-Jan-05 3:55 
GeneralRe: Runtime Exceptions Pin
jacquelin.potier8-Feb-05 1:50
sussjacquelin.potier8-Feb-05 1:50 
GeneralRe: Got 1 errors, 3 Warning Pin
jacquelin.potier5-Feb-05 5:36
sussjacquelin.potier5-Feb-05 5:36 
QuestionDid anyone got similar error ? Pin
scott_wu21-Dec-04 17:08
scott_wu21-Dec-04 17:08 
GeneralTCPSniffer Pin
Daniel Grunwald15-Oct-04 1:50
Daniel Grunwald15-Oct-04 1:50 
GeneralRe: TCPSniffer Pin
Anonymous15-Oct-04 7:30
Anonymous15-Oct-04 7:30 
GeneralMissing Resources Pin
kiddjoe11-Oct-04 6:00
kiddjoe11-Oct-04 6:00 
GeneralRe: Missing Resources Pin
rantanplanisback11-Oct-04 8:54
rantanplanisback11-Oct-04 8:54 
GeneralRe: Missing Resources Pin
rantanplanisback12-Oct-04 8:48
rantanplanisback12-Oct-04 8:48 
QuestionWarning CS0618. Can i fix it? Pin
Angel Tsvetkov11-Oct-04 0:31
Angel Tsvetkov11-Oct-04 0:31 
AnswerRe: Warning CS0618. Can i fix it? Pin
rantanplanisback11-Oct-04 8:51
rantanplanisback11-Oct-04 8:51 
GeneralRe: Warning CS0618. Can i fix it? Pin
rantanplanisback12-Oct-04 8:47
rantanplanisback12-Oct-04 8:47 
GeneralCapturing tcp Pin
Daniel Grunwald8-Oct-04 5:29
Daniel Grunwald8-Oct-04 5:29 

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.