Click here to Skip to main content
15,916,180 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I'm trying to make a connection between two computers both of them are using tp-link adapter , but i'm not receving anything from client .

<pre lang="C++">
<pre>#include <iostream>
#include<SFML/Network.hpp>
using namespace std;
int main()
{
    string lolz;
    cout << "C[CLIENT]/S[SERVER] : ";
    cin >> lolz;
    
    if (lolz.compare("S") == 0)
    {
        sf::UdpSocket socket;
        socket.bind(55002);
        char buffer[1024];
        std::size_t received = 0;
        sf::IpAddress sender;
        unsigned short port;
        socket.receive(buffer, sizeof(buffer), received, sender, port);
        std::cout << sender << " CLIENT SEND YOU : : " << buffer << std::endl;
        std::string message = "From server : Response is [ok]" + sender.toString();
        socket.send(message.c_str(), message.size() + 1, sender, port);


    }
    else if (lolz.compare("C") == 0){
        string ipSer;
        cout << "SERVER IP : ";
        cin >> ipSer;
        sf::UdpSocket socket;
        socket.bind(55001);
        // Send a message to IP on port 55002
        std::string message = "FROM CLIENT : [ok]  " + sf::IpAddress::getLocalAddress().toString();
        socket.send(message.c_str(), message.size() + 1, ipSer, 55002);
        char buffer[1024];
        std::size_t received = 0;
        sf::IpAddress sender;
        unsigned short port;
        socket.receive(buffer, sizeof(buffer), received, sender, port);
        std::cout << sender << " SERVER SEND YOU : : " << buffer << std::endl;
    }
}




What I have tried:

i tried to turn off firewall , antivirus
changing the ports
....
Posted
Comments
Richard MacCutchan 26-Sep-22 15:31pm    
What IP address are you using to connect the two devices?
jeron1 26-Sep-22 17:20pm    
Verify that you're sending the proper data on the proper interface first. Wireshark is a great tool to see what's going on sending and receiving with your network ports.

1 solution

I would try running this from a command line, with some adjustments for that to make it a simple command. Get that to work then add to that a little at a time. Maybe then try moving that to PowerShell. Get that to work then add more until you have a stable result. Then convert the PowerShell to C++. I know that I did not give you any code, but I did not find a problem with your code as it is, so maybe there is a problem somewhere else. That I how I might look for the outside problem: start simple, very simple, then add a little at a time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900