The MASM Forum

General => The Campus => Topic started by: gelatine1 on April 26, 2015, 06:09:55 AM

Title: connecting using winsock
Post by: gelatine1 on April 26, 2015, 06:09:55 AM
Hello

I created a small server and a client program. The client tries to establish a connection with the server and then sends data to the server. Everything works fine as long as my client uses a local ip address (and also works with 192.168.0.1 or 127.0.0.1) , so i can only use this with computers who are connected to the same router.
Once I try to use my public ip address to find the server then it does not work anymore. I am not sure why this does not work with any 2 computers so can anyone help me out with this ?

the program is in attachments. To run you should first open up the server. once it is running you can change the ip address in the client assembly file if you want and then compile again. if you run the client.exe file you should normally receive a messagebox with "abcd" if everything went right.

Thanks in advance

Title: Re: connecting using winsock
Post by: Farabi on April 26, 2015, 10:00:16 PM
Hi,
By what I understood, you are using your internet IP to search for the server. As far as I also tried I cant do the same thing. You will need to register your laptop to the DNS server in order to made your computer accessible by other computer publicly. I also tried to use my IP address to directly transfer data, but it seems that IP address is not specific to my house, it was my ISP IP address, it chaged each time I reset my router, and it has a different password. The only thing you can do to made your software talked each other is by using a comercial webserver which their DNS is registered as a bridge.

I tried to use kite to made my android tablet to be a server, but none had succeed, if you found a way, let me know.
Title: Re: connecting using winsock
Post by: gelatine1 on April 27, 2015, 05:49:36 AM
Do you mean there is no other way than using a dns server to send and receive data between 2 computers over the internet ?
then where would be a good place to get this dns server to my computer ?
(I'm sorry if some of the things i say make no sense, since I am not very familiar with networking and similar (which i am trying to learn now))
Title: Re: connecting using winsock
Post by: dedndave on April 27, 2015, 06:33:57 AM
http://www.madwizard.org/programming/tutorials/netasm/ (http://www.madwizard.org/programming/tutorials/netasm/)

that's the first page - follow the arrows at the bottom
Title: Re: connecting using winsock
Post by: dedndave on April 27, 2015, 06:38:31 AM
FASt Server by James Ladd...

https://gist.github.com/jamesladd/720718 (https://gist.github.com/jamesladd/720718)
Title: Re: connecting using winsock
Post by: gelatine1 on April 28, 2015, 04:25:22 AM
thank you for that page dedndave. I tried to connect with the fast server too and the same issue occurs again. I am able to connect to the server as long as i keep using my local ip - address or 127.0.0.1. but once i tell my client to connect with the server at my public ip addres then it does not work anymore. Why is this and what exactly should i do so that i am able to make the client connect to the server through a public ip address.
Title: Re: connecting using winsock
Post by: Siekmanski on April 28, 2015, 04:39:11 AM
Check your router settings, maybe it blocks the port you are using.
Title: Re: connecting using winsock
Post by: dedndave on April 28, 2015, 04:44:31 AM
i don't really know - this is an area i haven't played with much

but, i think your server has to follow one of several protocols
examples:
HTTP, web server
FTP, file server
P2P, peer-to-peer
Title: Re: connecting using winsock
Post by: mabdelouahab on April 28, 2015, 10:01:58 AM
Hi gelatine1
I have never worked with ws2_32.dll, I worked with MSWinsockControl (MSWINSCK.OCX)
I remember that we must Define in the server: Protocol = sckTCPProtocol , and LocalPort= N then let it Listing
Client :RemotHost="ServerName OR ServerIp"; RemotPort= N; Then we Connect
You can call on the same computer, or on a local network or on the Internet; If you want, I will make an example for you
Title: Re: connecting using winsock
Post by: Farabi on April 28, 2015, 01:36:13 PM
Quote from: gelatine1 on April 27, 2015, 05:49:36 AM
Do you mean there is no other way than using a dns server to send and receive data between 2 computers over the internet ?
then where would be a good place to get this dns server to my computer ?
(I'm sorry if some of the things i say make no sense, since I am not very familiar with networking and similar (which i am trying to learn now))

Yes there is no way, I used a free server as a bridge between my tablet and my laptop for it. There is a way by downloading pagekite, but I have not tried it, basically kite also making a bridge between your device using a server, so basically it is the same. I dont think you will found a way to do this.
Title: Re: connecting using winsock
Post by: Siekmanski on April 28, 2015, 05:37:07 PM
Quote from: Farabi on April 28, 2015, 01:36:13 PM
Quote from: gelatine1 on April 27, 2015, 05:49:36 AM
Do you mean there is no other way than using a dns server to send and receive data between 2 computers over the internet ?
then where would be a good place to get this dns server to my computer ?
(I'm sorry if some of the things i say make no sense, since I am not very familiar with networking and similar (which i am trying to learn now))

Yes there is no way, I used a free server as a bridge between my tablet and my laptop for it. There is a way by downloading pagekite, but I have not tried it, basically kite also making a bridge between your device using a server, so basically it is the same. I dont think you will found a way to do this.

Yes there is,
Ask your provider for a static ip address.
If this is not possible but your provider offers you web space, you can upload your ip address when you start your server on your computer.
You can get your current ip address via http://checkip.dyndns.org/
Now the clients can get the ip address for your server by downloading it from your web space.
Title: Re: connecting using winsock
Post by: gelatine1 on April 29, 2015, 06:35:30 AM
Quote from: Siekmanski on April 28, 2015, 04:39:11 AM
Check your router settings, maybe it blocks the port you are using.

Yes i checked my ports and it appears that all my ports are closed. Ill try to open some of them up later when i can and ill see if the program does work then.
Title: Re: connecting using winsock
Post by: Siekmanski on April 29, 2015, 08:20:43 AM
Look for this: Port Forwarding, also called Inbound Firewall Rules.

type: cmd
type: ipconfig (or ipconfig /all)

Now you can see these settings,

   Default Gateway . . . . . . . . . : 192.168.1.1 (the ip address to access your router software)

   IPv4 Address. . . . . . . . . . . : 192.168.1.10 (the ip address to forward your port number to)

Just found an old example i wrote based on source code from a guy named Pauly (if i'm correct..)
I had to forward the port for this proggy in my router software to get the server running.

Here is a client example so we all can chat with each other now. ( i'll let the server running on my PC for a while.... )
Title: Re: connecting using winsock
Post by: dedndave on April 29, 2015, 09:52:10 PM
i think 192.168.0.1 is used to access the router software
192.168.1.1 is the gateway

my current local IP is 192.168.1.100
but, the router may assign other values to the last byte (.104 - whatever)
it depends on how many computers are connected prior to establishing a connection

however, you can change the router settings to get a fixed value
in the past, i have used port forwarding
i set up the router so that my computer was always assigned .108

that's all local stuff (LAN) - not related to the IP that's visible outside my LAN
Title: Re: connecting using winsock
Post by: jj2007 on April 29, 2015, 10:02:55 PM
Siekmanski_Chat.exe seems to work here, but I'm the only person online...
Title: Re: connecting using winsock
Post by: fearless on April 29, 2015, 10:46:42 PM
just connected, then seen jj, then he left.  :( now im all alone.
Title: Re: connecting using winsock
Post by: jj2007 on April 30, 2015, 02:53:19 AM
Hey, I didn't leave, I was just a bit absent...
Title: Re: connecting using winsock
Post by: gelatine1 on April 30, 2015, 04:37:38 AM
Okay so I tried to go to the 192.168.0.1 and 192.168.1.1 in my browser but i get a ERR_CONNECTION_REFUSED. (in chrome). I also checked with ipconfig if my default gateway is not something else but it actually is 192.168.0.1. Does anyone know why this doesn't work ? I also asked my dad for the disk of the router but it contained nothing but a pdf that told me I should go to 192.168.0.1...
Then I went to my firewall settings and I set an inbound rule to open up a few ports on TCP and any kind of connection. this seemed to work but when I checked again on http://ismyportopen.com/ it still said my port is closed. (is this site reliable ?).
Is there anyone who knows what might be going on ? or what I could do to get the port open ?

thanks in advance
Title: Re: connecting using winsock
Post by: Siekmanski on April 30, 2015, 05:08:08 AM
You have to do this in the router software. Can you get access to the router now ?
You need to forward the port number of your proggy to your local ip address. ( you can look it up via ipconfig )

Yes it's reliable, http://ismyportopen.com/ tells me that the port i use is open.

Try a higher port number, 2121 will do.
You are using port number 23, that's the Telnet port number.

Ports numbers 0 to 1024 are reserved for privileged services.
Title: Re: connecting using winsock
Post by: dedndave on April 30, 2015, 05:30:44 AM
ok - i just tried it on my router
as Marinus mentioned, it IS 192.168.1.1
and - a dialog pops up, asking for the ID/password, as expected (verified firefox and IE)

if you don't know the password....

most routers can be reset

google your router make and model to see what the default ID/password is - and how to reset it
try the default ID/password before continuing, as it may still be the default

on mine, i hold the reset button down, power up, and continure to hold the button for 30 seconds
this resets all the router settings, including the password
Title: Re: connecting using winsock
Post by: fearless on April 30, 2015, 06:50:34 AM
3 of us on so far, come join us
Title: Re: connecting using winsock
Post by: Siekmanski on April 30, 2015, 08:30:20 AM
Stopped the server on my PC, chat session is closed.

Marinus
Title: Re: connecting using winsock
Post by: Farabi on May 02, 2015, 08:41:00 PM
Quote from: Siekmanski on April 30, 2015, 08:30:20 AM
Stopped the server on my PC, chat session is closed.

Marinus

Whoa, you can do it? I never though it possible.
Title: Re: connecting using winsock
Post by: dedndave on May 02, 2015, 09:13:05 PM
in this case, the "server" is a program that he runs
Title: Re: connecting using winsock
Post by: Siekmanski on May 03, 2015, 04:32:05 PM
Quote from: Farabi on May 02, 2015, 08:41:00 PM
Quote from: Siekmanski on April 30, 2015, 08:30:20 AM
Stopped the server on my PC, chat session is closed.

Marinus

Whoa, you can do it? I never though it possible.

Yes, you can run a server on your own PC wich handles all the incoming data traffic from several clients.
If one client sends a message, the server sends back this message to all the other connected clients.

Server side:
Must have an open port to allow incoming data to the server.
A router blocks the ports so you need to open the port number you want to use via the router software. ( port forwarding )
The port number will be forwarded to your local ip address ( the one behind the router thus your PC in your local network )

Client side:
Don't need to open a port on there PC.
The client only needs to know the ip address of the server and the port number of the server.

jj2007, fearless and I had a chat with each other this way.  :biggrin:  ( the server was running on my PC )
Title: Re: connecting using winsock
Post by: gelatine1 on May 05, 2015, 04:21:31 AM
I have tried to forward a port but i can't acces the routers software so I guess I will just test everything on my local internet until I find a way to access the router software...
Title: Re: connecting using winsock
Post by: Siekmanski on May 05, 2015, 07:46:59 AM
Search the internet for your router make and model and how to reset the router software.
Then you can access the router again.