Search code examples
vb.netsocketsports

How to make a winsock listen on a particular port?


This must be really obvious, but how do I make a winsock listen to a specific port (recieve data?) I cannot find a method that lets me do so!

Sorry that this is probably so obvious.

I am trying to make a chat application, which is obviously running in a server/client setup.


Solution

  • You bind the socket, and then listen and accept connections. Described in more detail in Getting started with WinSock. There's also a good guide to the BSD sockets, which you should read too.

    For .NET, you probably want System.Net.Sockets.Socket (and it's Bind/Listen/Accept/Send/Receive methods) instead of native WinSock, but the concepts are the same, so I'll leave all links.