The MASM Forum

General => The Workshop => Topic started by: felipe on March 06, 2019, 10:08:19 AM

Title: winsock fun
Post by: felipe on March 06, 2019, 10:08:19 AM
I have been working with winsock (more especifically with ws2_32.dll). So i made a little demo-test-unfinished program. Actually 2 programs: the server and the client. So, after both programs establish connections (i'm using tcp), the client send 256 bytes (the classical happy face 02h), then the server shows all those characters received from the client in a simple console. The program works ok and does exactly just that, when both programs are using the localhost address (127.0.0.1).
Now the problem:
I tried this same programs in differents computers using the internet. So i settle the computer with the server: configured the software of the router creating a virtual server in a nat, assigning the port. And in the code the client was addressing the public ip address of the router. But the program dosen't work as expected. The weird issue is that from the client program of one of the computers i run the program using a debbugger, which shows me that's all right, not error codes at all. But in the "server side" (in the other computer) i can't see the characters.
Just an overview:
1)computer running the client program try to reach the public ip of the router in port 80 (i have tried 8080 too). The debbuger shows that connect has no errors neither send (connect and send functions).
2)computer running server is behind a nat, the router has it as virtual server, with a local ip using port 80. The server uses in the code INADDR_ANY as address (but i have tried with the local one and with the public one too).
3)both programs communicate without issues using the same computer, using the localhost address (ip 127.0.0.1).

Any help it's well appreciated... :icon14:
Title: Re: winsock fun
Post by: Raistlin on March 06, 2019, 04:06:08 PM
Hail Felipe  8), without much to go on, this sounds like a firewall or port forwarding issue (<- most probable).
Also try using utilities such as Packet Sender, NetCat or similar; to detect and emulate your client - should reveal
whether you have direct server connectivity/communication. Hope this helps - Raistlin
Title: Re: winsock fun
Post by: felipe on March 06, 2019, 11:57:53 PM
Thanks raistlin i will try some of those tools to make a diagnost.  :icon14:
Title: Re: winsock fun
Post by: Raistlin on March 12, 2019, 04:05:17 PM
Any update Felipe ? I'am just interested in network code of any flavor. I've got some free time
towards the end of the month set aside for special projects. Feel free to PM me if you would
like to share thoughts.
Title: Re: winsock fun
Post by: felipe on March 12, 2019, 10:11:26 PM
i will try to do something today, i will share the results.  :icon14:
Title: Re: winsock fun
Post by: Lonewolff on March 13, 2019, 02:23:27 PM
The server PC is likely blocking the incoming traffic. A quick test to confirm this would be to disable the firewall on the PC.
Title: Re: winsock fun
Post by: felipe on March 13, 2019, 11:38:41 PM
I have enable the incoming traffic for the server program in the pc server, in the windows firewall, but still no luck. i will add to both programs (client and server) some messages to show the status of the program, to better have and idea of what is happening.
is it possible that is because the client pc has a wifi internet connection?  :idea:
Title: Re: winsock fun
Post by: Lonewolff on March 14, 2019, 08:20:27 AM
No the type of connection shouldn't be a problem.

What about disabling the firewall entirely, instead of making exceptions. This will outright tell you if it is a firewall problem or whether you are facing a totally different issue.  :idea:
Title: Re: winsock fun
Post by: aw27 on March 14, 2019, 08:35:53 AM
Quote from: felipe on March 13, 2019, 11:38:41 PM
I have enable the incoming traffic for the server program in the pc server, in the windows firewall, but still no luck. i will add to both programs (client and server) some messages to show the status of the program, to better have and idea of what is happening.
is it possible that is because the client pc has a wifi internet connection?  :idea:

Download some old Microsoft SDK samples, for example from the Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (new SDKs are full of new experimental technologies that obfuscate reality and turn programmers completely dumb).
Title: Re: winsock fun
Post by: felipe on March 14, 2019, 10:40:18 AM
Quote from: AW on March 14, 2019, 08:35:53 AM
Download some old Microsoft SDK samples, for example from the Windows SDK for Windows 7 and .NET Framework 3.5 SP1

i prefer not to do that, there are more sources of information about winsock programming. anyway, aren't this samples written in c++?  :idea:
Title: Re: winsock fun
Post by: aw27 on March 14, 2019, 06:38:34 PM
Quote from: felipe on March 14, 2019, 10:40:18 AM
Quote from: AW on March 14, 2019, 08:35:53 AM
Download some old Microsoft SDK samples, for example from the Windows SDK for Windows 7 and .NET Framework 3.5 SP1

i prefer not to do that, there are more sources of information about winsock programming. anyway, aren't this samples written in c++?  :idea:
There huge sources of information about winsock programming and a basic client/server is expected to always work, something you are having problems with.
Title: Re: winsock fun
Post by: felipe on March 14, 2019, 10:34:33 PM
Quote from: AW on March 14, 2019, 06:38:34 PM
a basic client/server is expected to always work, something you are having problems with.

This is not true at all. i mean maybe it will almost always work in the same computer (localhost). but in the internet the issues are very common.  :idea:

Quote from: Ascended on March 14, 2019, 08:20:27 AM
What about disabling the firewall entirely, instead of making exceptions. This will outright tell you if it is a firewall problem or whether you are facing a totally different issue.  :idea:

I will try that too.  :icon14:
Title: Re: winsock fun
Post by: TimoVJL on March 14, 2019, 10:50:34 PM
also check if there is a routing problems.
ping ?
netsh interface ipv4 show neighbors ?
Title: Re: winsock fun
Post by: felipe on March 14, 2019, 11:39:00 PM
that was a good idea timo  :icon14:. ping is a simple cmd command/program to test any connection. without the need to re-test the client/server programs, i set up the pc server and in the client pc run the ping command/program with the server ip. i received as output all the packets lost. so the problem is related with the router where i configure the pc server. maybe the ports i have tried are no good ones. i have tried 80, 8080 and 5150. anyone knows of a safe port (that normally works in most cases without having conflicts witho other programs in the computer using port connections) to try out?  :idea:
Title: Re: winsock fun
Post by: felipe on March 14, 2019, 11:43:59 PM
and ping doesn't connect successfully either if i completely disable the windows firewall.  :(
But i will keep trying :biggrin:.
Title: Re: winsock fun
Post by: hutch-- on March 15, 2019, 12:11:20 AM
felipe,

If you are not using an existing service port, you can use anything up to 64k from memory. Years ago I did some work at both HTTP and UDP communications between 2 computers and it worked OK but I cheated and use high level code to do it, not raw winsock.
Title: Re: winsock fun
Post by: aw27 on March 15, 2019, 12:13:17 AM
Quote from: felipe on March 14, 2019, 11:43:59 PM
and ping doesn't connect successfully either if i completely disable the windows firewall.  :(
But i will keep trying :biggrin:.

All you need to do is enable ICMP echo request on the target PC. If there is no rule for that you need to make a new rule, but I think windows 8 has the rule but is disabled.