locked
How do I make both a server and client TCPIP socket

    Question

  • How do I make both a server and client TCPIP socket. I used to do this all the time in VB6 using winsock. How do I do the same thing in C#.

    Sunday, September 03, 2006 10:59 PM

Answers

  • Works similarily in .NET.  The Socket class can be used to send and receive data through TCP/IP.

    Create an instance of the Socket class for the address you want to monitor.  Use Listen on the server side to begin listening for requests.  When a request comes in use Accept to accept the request.  You should consider accepting and processing accept requests on a secondary thread to avoid having the server stall while you process each request.  This can be done by accepting the request and then passing it along to a secondary thread that deals with the request.

    On the client side create an instance of Socket on which you want to send data.  Use the Connect method to connect to the server.  Use Send/Receive to send and receive data.

    For asynchronous operations you'll find Begin-/End- methods for most of the above methods as well.

    Michael Taylor - 9/3/06

    Monday, September 04, 2006 5:00 AM
    Moderator

All replies

  • Works similarily in .NET.  The Socket class can be used to send and receive data through TCP/IP.

    Create an instance of the Socket class for the address you want to monitor.  Use Listen on the server side to begin listening for requests.  When a request comes in use Accept to accept the request.  You should consider accepting and processing accept requests on a secondary thread to avoid having the server stall while you process each request.  This can be done by accepting the request and then passing it along to a secondary thread that deals with the request.

    On the client side create an instance of Socket on which you want to send data.  Use the Connect method to connect to the server.  Use Send/Receive to send and receive data.

    For asynchronous operations you'll find Begin-/End- methods for most of the above methods as well.

    Michael Taylor - 9/3/06

    Monday, September 04, 2006 5:00 AM
    Moderator
  • That was exactly what I was looking for, Thannks
    Saturday, September 09, 2006 5:43 PM