From: | Patrick Roberts |
Date: | 2 Sep 2000 at 17:52:58 |
Subject: | Re: AMIOPEN: Socket Help |
Thanks Rudi-
I did just throw in the instance thing to get around the fork in the test
program (there's a readme with how to run it under the SDK).
Thanks for the info on the bind() call- I'll also check out the server errors.
Thanks again,
Pat
Rudi Chiarito wrote:
>
> On Fri, Sep 01, 2000 at 06:27:52AM -0700, Patrick Roberts wrote:
> > Could someone more familiar with sockets than I am help me out. I started a
> > port of libeasy_sock (socket library I've used under Linux). I've got it
> > compiling fine, but when I run the test it gives me an error about the socket
> > being busy. Could someone take a look at it? It's been uploaded to the CVS
> > server as libeasy_socket.
>
> The problem(s) is (are) in the test program, which seems to have been
> adapted from a typical Unix (ie forking) program in a hurry.
>
> First of all, there's argument checking:
>
> if (argc > 2 && argc < 4) {
> usage(argv[0]);
> exit(0);
> }
>
> If I run the program with no arguments (which is the first thing I did),
> the check above fails to print the usage message and bail out.
> Immediately after that, there's this call, which will cause an access to
> an illegal memory address, because there's no valid argv[1]:
>
> instance = atoi(argv[1]);
>
> I suppose you might want to change to above to something like "argc != 2
> && argc != 4)".
>
> Then, for both the client and the server, you call bind(). That's why you
> find a busy socket. The client should use connect(), which, for a
> not-yet-bound socket, automatically calls bind(), telling it "allocate
> any of the free ports". After changing the one-line bind() statement to
>
> if (instance == 0)
> sock = easy_tcp_bind(host1,port1,BACKLOG);
> else
> sock = easy_tcp_connect(host1,port1);
>
> the client runs successfully with this output:
>
> 20000807:/libeasy_socket$ ./easy_test_Ami 1
>
> Client (155): Connecting to 127.0.0.1 on port 7001...done.
> == 155 == Write char: 'e'
> == 155 == Write short: 127
> == 155 == Write int: 2147483647
> == 155 == Write long: -9223372036854775808
> == 155 == Write float: 4010.000244
> == 155 == Write double: 2000.010400
> == 155 == Write string: "This is a test string"
> == 155 == Write char: 'E'
> == 155 == Write short: -128
> == 155 == Write int: -2147483648
> == 155 == Write long: 9223372036854775807
> == 155 == Write float: 1234.002930
> == 155 == Write double: 2050.014800
> == 155 == Write string: "This is another test string"
> Client (155) test completed.
>
> The server complains with several error messages, you might want to check
> carefully the test and the library to find what's wrong.
>
> --
> "Without deviation from the norm, progress is not possible." (F. Zappa)
> Rudi Chiarito SGML/XML, user interface, i18n Amiga Inc.
> rudi@amiga.com http://amiga.com/
> Subscribe/Unsubscribe: open-request@amiga.com
> Amiga FAQ: http://www.amiga.com/faq.html
Subscribe/Unsubscribe: open-request@amiga.com
Amiga FAQ: http://www.amiga.com/faq.html