Sign in to follow this  
mnbvlk

socket help

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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??????????

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote]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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
suppose iam on a site A .Now i want to check the connection between two other sites B and C . can pinging router which is between B and C can be done while iam on site A???

if ping sucessful can we say B and C are connected properly

Share this post


Link to post
Share on other sites
Quote:
Original post by mnbvlk
suppose iam on a site A .Now i want to check the connection between two other sites B and C . can pinging router which is between B and C can be done while iam on site A???

if ping sucessful can we say B and C are connected properly
Can't be done, because of the way the Internet is structured. The best you could achieve would be to ask site B to ping site C. But that requires you to have control over site B.

Share this post


Link to post
Share on other sites
Quote:
Original post by mnbvlk
even if the network belongs to a particular company can i then also not ping
I don't understand, sorry. Just because A can ping B and C, it doesn't mean that B and C are connected in any way.

Pings only work from one point - they're just a packet with "please reply" stamped on it. When you send a ping packet to a target IP address, that machine sends a packet back to where the ping came from (The IP address is stamped on the way out). However, not all machines respond to ping - for instance most reouters have an option to not respond to pings.

Quote:
Original post by mnbvlkif not , can socket programming help me. if yes ,how??????????????
Nope.

What exactly are you trying to do? I'm having difficulty understanding what pinging two sites (I assume you mean websites?) has to do with connecting two corporate networks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this