socket help

Started by
12 comments, last by Evil Steve 16 years, 2 months ago
how to create a socket ( in dev c++ 4.9.9.2) between my comp and 64.233.187.99 (which is google.com) i tried SOCKET sockfd; sockfd=socket(AF_INET,SOCK_STREAM,0); but does not know the meaning of various arguments i.e where to specify the ip address can anybody help please thanks in advance
Advertisement
This is a very good tutorial concerning linux sockets.
http://beej.us/guide/bgnet/
The socket() just creates a file descriptor.
Then you have to use the bind() command in which you give the ip and port number.
The tutorial says it all :P
sorry , i forget to tell that iam working on windows xp and not linux
http://devmentor.org/articles/network/Socket%20Programming.pdf
That shoul do it :P
thanks for the links

i have another question ( i am actually a beginner in networks)

can two networks placed far apart in different towns can be connected by a router

also is something exists like this == ip address of a router .if it exists , then what does it mean

again remember ( i am actually a beginner in networks so questions may be strange)
Quote:Original post by mnbvlk
sorry , i forget to tell that iam working on windows xp and not linux
Beej's Guide is 99.9% relevant to WinSock too. The only differences I can think of offhand are that you need to call WSAStartup before making any socket calls, and the first argument to select() is ignored in WinSock.
Quote:Original post by mnbvlk
thanks for the links

i have another question ( i am actually a beginner in networks)

can two networks placed far apart in different towns can be connected by a router

also is something exists like this == ip address of a router .if it exists , then what does it mean

again remember ( i am actually a beginner in networks so questions may be strange)




are my questions strange??????????
Quote:Original post by mnbvlk
can two networks placed far apart in different towns can be connected by a router
Yes they can. Although they're likely to be connected by several routers (This is essentially how the Internet works).

Quote:Original post by mnbvlk
also is something exists like this == ip address of a router .if it exists , then what does it mean
I don't quite understand what you mean. Your external IP is assigned by your ISP, and your internal LAN IP is assigned by your router (Assuming you have DHCP enabled). If you're asking if there's a way to get the IP of your router, then yes - you can get the default gateway through some Winsock calls. But that'll be your router's internal LAN IP (E.g. 192.168.0.1), not it's external IP as other machines see it.
Original post by Evil Steve
Quote:Original post by mnbvlk
can two networks placed far apart in different towns can be connected by a router
Yes they can. Although they're likely to be connected by several routers (This is essentially how the Internet works).

will there be several routers even if the networks is a private lan spread all over a city or just a single router


Quote:Original post by mnbvlk
will there be several routers even if the networks is a private lan spread all over a city or just a single router
Depends on the network. Although almost definitely - one router won't really be able to cope well with hundreds or thousands of connections.

This topic is closed to new replies.

Advertisement