TCPClient and TCPListener connection problem

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey guys,

<div style="text-align:left Ill try and keep this short :

<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% public class Server
{
        public Server()
        {
            server = new TcpListener(IPAddress.Parse("127.0.0.1"), 1862);
        }

        public void Start()
        {
            server.Start(1);
            ListenForConnections();
        }

        private void ListenForConnections()
        {
            client = server.AcceptTcpClient();
            InitialiseConversation();
        }
}


<div style="text-align:left and :
<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% public class Client


<div style="margin-left:40px <span style="width:100% public bool Connect(string address)

<div style="margin-left:40px <span style="width:100% <span style="width:100%         {
            try
            {
               TCPClient client = new TCPClient();<span style="width:100%

<div style="margin-left:120px <span style="width:100% client.Connect(address, 1862);

<div style="margin-left:40px <span style="width:100% <span style="width:100%             }
            catch
            {
                return false;
            }

            netStream = messenger.GetStream();
            return true;
        }
}


Well, as youd expect, i start the server, then the client.  This works 100% as expected when running the server AND the client locally.

However, i sent the server to my brother to test it, but I cant connect to it.  Ive checked the following so far :

1)  Started the server on a remote pc.
2)  netstat -a on remote PC shows as listening on port 1862.
3)  Client attempts to connect using remote pcs remote name.
4)  netstat -a on client PC shows as SYN_SENT to the correct IP Address (which has been translated from the name, therefore obviously the hostname was successfuly translated to ip).
5.  Client fails to connect due to timeout/no response from server.

I have forwarded port 1862 of the remote router to the PC of the server i am trying to connect to.

Now I am at a loss as to what I should try next - any suggestions?  As i mentioned earlier, this works fine when server and client are run locally, but i fail to see what other obstacles could be blocking the connection now.

Many thanks.


<div style="text-align:left

<div style="text-align:left


View the full article
 
Back
Top