socket

Started by
32 comments, last by Tran Minh Quang 21 years, 6 months ago
Does anyone know about socket programming? Please help me this problem I have 2 programs: 1 used for client side and 1 for server side. I want to test them in my computer but i have only ONE computer without any network connection. How can I? I''ve heard that we can test them in one-single computer without network (in Beej''s PDF tutorial - you can find it easilly) but when i try my program, Client program say: connect() failed. Infact i think the program is totally right because i copied it from a famous author. So there must be something wrong happen in the way i try to test the program. So please tell me How can I test a socket program when i have only 1 computer without network connection (step by step please, i insist you since i am newbie) PS: I use Winsock instead of UNIX
Advertisement
I am studying from the same tutorials too. Just setup your server, create a port, and have the client(which is the same computer) connect to it. It doesn''t matter that it''s the same IP address. You don''t need a network to do this, just an internet connection. Of course there is no joy in connecting to yourself. Maybe you can have somebody download your program (client software), and test it for you. Thats what I did when I first started winsock programming

I don''t have a signature
I don't have a signature
A network connection is not needed to run a local client/server pair. Simply ensure that the client uses the localhost address in its call to inet_addr(). The localhost address basically redirects all connections back to the originating computer so that a client and server running locally may communicate. The IP address that you''d want in this case is the loopback IP, 127.0.0.1.
________________________________________________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
quote:
setup your server and open a port

Can you tell me more about it. Is it the process of running Server program in a Window?. I will tell you more detail what i did:
I''ve got 2 program that i type exactly what a author of book did (Do you know the book: Pocket TCP/IP socket programming?) and want to test it on my computer. What i did is:
1) I open a Dos-prompt window. Type the name of my server program with argument and let it run
2)Open another Dos-prompt window. Type the name of my client program with argument (with IP = 0.0.0.0) and press enter.
My Client program failed with error: "send() failed".
I don;''t know why?

PS: For anyone know the book i told above. What I test is:
Server:
TCPEchoServer 5000

Clien
TCPEchoServer 0.0.0.0 "Echo this!" 5000
connect() failed: 10065 (or 10079...?)

I don;t know if i must give another IP address?. From Run i type winipcfg and get my IP address 0.0.0.0 so i think it is correct command?
Hope you help!



You can use the loopback device : just connect to address 127.0.0.1 which is ALWAYS the local machine. That way you can run the client and the server on the same machine.

As for the error, well, you need to check the error code (have the program print it out) to find out WHY connect() fails.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Sorry if this is a stupid question. But can you explain the method you said Jones?
quote:
Maybe you can have somebody download your program (client software), and test it for you.

Can you explain more detail Jones? I really want the method you used because infact it make us to test program in real condition


this is my code:

//Socket descriptor
SOCKET sock;

if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALIDE_SOCKET)
{
perror("connect() failed");
exit(0);
}

it is the very first command in Client program so i don;''t know why it does not works?
help please!
I was going to suggest you download a copy of Apache and run that on your local machine to get a feel for local networking and connecting to 127.0.0.1 (localhost) - but if you don''t have enough bandwidth you might try something smaller and simpler such as Zeroo HTTP Server. Launch it from a console (DOS box) and then connect to it from a browser. And not to disuade you from continueing forward with Beej''s tut, but you might also find this website helpful: Internet programming crash course
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Use AF_INET for the first parameter in socket()

I don''t have a signature
I don't have a signature
I tried but still not work

[edited by - Tran Minh Quang on September 25, 2002 12:41:52 AM]

This topic is closed to new replies.

Advertisement