Yanshof
Yanshof

Reputation: 9926

connecting to port using TcpListener class

** I don't have much experience with sockets and network develop - so im sorry if this question is not very good ...

I have some hardware that connected to my computer ( i see this hardware as network card ). This hardware is sending some strings using TCP protocol ( sending always to port 551 ).

New, i need to get those string in my application. So i want to use the 'TcpListener' object to listen to localhost protocol - listen to port 551.

In the MSDN i see that i can initialize the 'TcpListener' object so it will listen always to port 551 ( first constructor ).

But the hardware is also connected to port 551 - because its need to be send the strings -

So how can i do it ? what is my basic misunderstanding ?

Upvotes: 1

Views: 2014

Answers (1)

DanTheMan
DanTheMan

Reputation: 3277

First, make sure I have the setup correct:

So you have some hardware sending it out on port 551, say on IP Address 192.168.1.1. You added a second card, with, say, IP Address 192.168.1.2.

In order to listen to what 192.168.1.1 is sending you need to:

1) Make sure 192.168.1.1 is sending its TCP Packets to port 551 on 192.168.1.2.

2) Open a TCPListener, binding the listener to 192.168.1.2:

IPAddress localAddr = IPAddress.Parse("192.168.1.2");
TcpListener server = new TcpListener(localAddr , 551);

3) Sit and wait until server finds something coming in on that port:

server.Start();
...
server.AcceptTcpClient();

Upvotes: 2

Related Questions