how to tell a socket what port to listen to?

fguihen

Well-known member
Joined
Nov 10, 2003
Messages
248
Location
Eire
i have to create a socket (in C#) and tell it to listen to the Irda port on my laptop. i havnt a clue how to do this , as all examples are specifying IP addresses. anyone help me?
 
well, im not sure about IrDA, but with a regular socket class you can specify the port in the endpoint that the socket listens to, like this:

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);

Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );

listener.Bind(localEndPoint);
listener.Listen(number_of_backlogs);

then you can do a listener.Accept() and listener.Recieve(),

Theres a really good tutorial on sockets in the msdn.


Jimmy
 

Similar threads

B
Replies
0
Views
372
Blue Baron
B
P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
Back
Top