I have a card game developed in c#. I wanted to make it work over network, however, I managed to make it work over LAN only. I browsed lots of pages, and didn't find an answer for my problem.
I am using System.Net.Socket object. The application has asynchronous connections and all. One side is client, other is server. In order to connect two computers (my computer is behind router), i should make some server (theoretically),that is publicly visible, and players will connect to it. Or set a static (visible, unique) IP adress for my PC. I do not want to do these, so I tried to forward ports.
I forwarded the port 906, and also allowed it in firewall for incoming requests. I set it all to both TCP and UDP. I hosted a connection with server.
public static int PORT = 906;
public static Socket HostSocket;
HostSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress IP = IPAddress.Any;// Functions.GetThisMachineIPv4();// IPAddress.Any;
HostSocket.Bind(new IPEndPoint(IP, PORT));
HostSocket.Listen(3);
HostSocket.Blocking = false;
HostSocket.BeginAccept(new AsyncCallback(BeginAcceptConnection), HostSocket);
To make it easier to understand: IPAdress is IP.Any (0.0.0.0), and port is the one...906
The client:
public static IPAddress IP = System.Net.IPAddress.Parse("XXX");
public static int PORT = 906;
client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client_socket.Blocking = false;
client_socket.BeginConnect(IP, PORT, new AsyncCallback(OnConnect), client_socket);
Please note, that instead of the "XXX" string as IP, I put there my default gateway, witch i got from command prompt.
Aditional info, maybe useless, but I have Internet Protocol ver. 4
However, despite days of studying pages and debugging, I have no idea, where else could be the problem, or what I did wrong.
Thank you for your time, and possible suggestions, or even solutions.

New Topic/Question
Reply



MultiQuote




|