Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Client-serwer communication (TCP) via global IP  (Read 1972 times)

0 Members and 3 Guests are viewing this topic.

marianexyx

  • Newbie
  • *
  • Posts: 11
    • View Profile
Client-serwer communication (TCP) via global IP
« on: January 11, 2015, 10:18:11 pm »
Hello. I wrote the simpliest client and serwer applications that can send a message. It works in local IP, but the same code wont work when I changed local IP to global IP. I have already tried to change internet connection, switch client<-> serwer, diffrent ports, but still nothing. Is my code wrong? Im the beginner with coding and I dont know internet structures well. I've already forward ports on my router and checked it works on program "port checker". Here is the code for client and serwer:

//serwer
#include <SFML\Network.hpp>
#include <iostream>
#include <conio.h>

using namespace sf;
using namespace std;

int main()
{
        UdpSocket socket;
        unsigned short s = 50001;
        unsigned short k = 50002;
        socket.bind(s);
        string tmp = "";
        Packet pakiet; 
        IpAddress ip_k = "89.66.209.51"; //can't work
        //IpAddress ip_k = "192.168.0.12"; //works
        socket.receive(pakiet, ip_k, k);
        pakiet >> tmp;
        cout << tmp;
        getch();
}

//client
#include <SFML\Network.hpp>
#include <iostream>
#include <string>
#include <conio.h>

using namespace sf;
using namespace std;

int main()
{
        UdpSocket socket;
        unsigned short s = 50001;
        unsigned short k = 50002;
        socket.bind(k);
        string tmp = "message";
        Packet pakiet;
        //IpAddress ip_s = "188.146.82.158"; //can't work
        IpAddress ip_s = "192.168.0.12"; //works
        pakiet << tmp;
        socket.send(pakiet, ip_s, s);
        getch();
}

btw. sorry for my english

------------------------------------------------------------------------------------------
edit: Found where is my problem. Im using udp sockets and trying to make a tcp connection  :-[. Code has been repaired and it works now.
« Last Edit: January 11, 2015, 10:37:33 pm by marianexyx »

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Client-serwer communication (TCP) via global IP
« Reply #1 on: January 12, 2015, 04:39:39 am »
I'm glad you solved the problem. Another noteworthy point is to make sure that the server you are trying to access through the external (Global as you call it) IP has the correct ports open to allow traffic through. I'm guessing this isnt a problem for you right now but if you run into connection problems in the future it might be worth checking the ports on the server.