Client/Server connection problems

27 views
Skip to first unread message

Bobby

unread,
Dec 3, 2015, 10:27:02 PM12/3/15
to Haxe
I've followed the tutorial on client/server connections here, updating the code to use sys.net. Socket/Host rather than the old neko versions. The code works fine when I run the server/client on the same machine (Windows 7 laptop).

My home network includes a server with Ubuntu - I've installed neko on the machine, and the server code runs fine. However, I can't get the client (running on my laptop) to connect with it.

I've updated the IP address that the client looks for to the IP address of my router, and have set up port forwarding to direct incoming connections on the 5000 port to the Ubuntu server. I've also configured the firewall to allow connections on the 5000 port.

I doubt this is a problem with a 'dynamic' IP address for my home network - I am able to run several websites and FTP from the Ubuntu server. I assume if I was getting a different dynamic IP address each time I connected then this wouldn't be possible - though if I am mistaken here please let me know! The problem seems to be specifically in getting my client application to connect to the server.

I Include the code I'm using below for reference. I'd be grateful if anybody could provide suggestions as to what the problem might be here (I've spent the best part of 10 hours trying to figure this out!)

Thanks in advance,
Bobby



// file Server.hx
import sys.net.Socket;
import sys.net.Host;

class Server {
    static function main() {
        var s = new Socket();
        s.bind(new Host("localhost"),5000);
        s.listen(1);
        trace("Starting server...");
        while( true ) {
            var c:Socket = s.accept();
            trace("Client connected...");
            c.write("hello\n");
            c.write("your IP is "+c.peer().host.toString()+"\n");
            c.write("exit");
            c.close();
        }
    }
}



// file Client.hx
import sys.net.Socket;
import sys.net.Host;

class Client {
    static function main() {
        var s = new Socket();
        s.connect(new Host("localhost"),5000); // when trying to connect to the server I replace this with the IP in the format "XXX.XXX.XXX.XXX"
        while( true ) {
            var l = s.input.readLine();
            trace(l);
           
if( l == "exit" ) {
                s.close();
                break;
            }
        }
    }
}
Reply all
Reply to author
Forward
0 new messages