TCP Connection Problem /w Pocket PC Emulator

  • Thread starter Thread starter minying
  • Start date Start date
M

minying

Hi everyone!

I am experiencing a problem when trying to establish a TCP connection
between a

program running locally and another program running on the Pocket PC
emulator

provided by the .NET 2003 environment.

TCP listener:

try {
TcpListener listener;
listener = new TcpListener(IPAddress.Any, 8000);
listener.Start();

while (true)
{
Socket connection = listener.AcceptSocket();
...
} } catch (Exception ...) {...}

TCP client:

TcpClient client;
try
{
client = new TcpClient("localhost", 8000);
...
} catch (...) {...}

I started the first program (with the TCP listener), and then started
the second

one in the .NET IDE with the pocket PC emulator as the target for
deployment. Then

an exception was caught:

"No connection could be made because the target machine actively
refused it."

Can any one tell me how to fix this problem? Many thanks!
 
TCP client:

TcpClient client;
try
{
client = new TcpClient("localhost", 8000);
...
} catch (...) {...}

"No connection could be made because the target machine actively
refused it."

Can any one tell me how to fix this problem? Many thanks!

Normally, you do not need to specify the address of the client socket . The
cases where you would need to specify the address and port for the client
socket might involve a multi-homed host when connecting to another host and
that host only accepts connections from specific IP addresses or from
specific ports.. Blocked ranges of ports using firewalls may be another
case.

The WinSock implementation will construct the socket and bind it to an
available local address and port if you attempt to conect using an unbound
socket. However, to specify the IP address for the TcpClient object, try
something like this:

TcpClient clSock;
IPAddress iaddr = IPAddress.Parse("121.9.9.109");
IPEndPoint endp = new IPEndPoint(iaddr, 8000);
clSock = new TcpClient(endp);

or this:

TcpClient clSock;
IPAddress iaddr = Dns.Resolve("localhost").AddressList[0];
IPEndPoint endp = new IPEndPoint(iaddr, 8000);
clSock = new TcpClient(endp);

Use this if you are OK with the system assigned values for the client :

TcpClient clSock;
clSock = new TcpClient();

regards
roy fine
 
Back
Top