tags:

views:

45

answers:

2

What's wrong with this please? It throws this error: "Attempting to deserialize an empty stream" at server side in this line when I run the server: "this.tcpListener.Start();" This is my internet IP, if I use my local IP, it works. But i want the internet IP.

Client side:

TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
tcpclnt.Connect("187.115.131.44", 8001);

Server side:

    public Server()
    {
        try
        {
            IPAddress ip = IPAddress.Parse("187.115.131.44");
            tcpListener = new TcpListener(ip, 8001);
            listenThread = new Thread(new ThreadStart(ListenForClients));
            listenThread.Start();
        }

        catch (Exception e)
        {
            Console.WriteLine("Error..... " + e.StackTrace);
            Console.ReadKey();
        } 

    }

    private void ListenForClients()
    {
        this.tcpListener.Start();

        while (true)
        {
            //blocks until a client has connected to the server
            TcpClient client = this.tcpListener.AcceptTcpClient();

            //create a thread to handle communication
            //with connected client
            Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
            clientThread.Start(client);
        }
    }
+1  A: 

The firewall and/or router/switch you are obviously behind is the cause. It would require a change or an addition of a NAT policy on said appliance.

Gregory Kornblum
yes..its a router..damn it, i dunno configure it, i've tried a lot =/thanks anyway
Alan
+1  A: 

When you start your application and are listening on a port, run a port forward check here.

I've had this problem when writing network software - it's a common problem.

Once you've verified that its a port forwarding problem, head over to PortForward.com. There are great resources there to help you configure your router.

Charlie Salts
thank you! nice site
Alan