Establishing a socket between a perl client a c server

Establishing a socket between a perl client a c server

Post by Noon » Fri, 08 Jun 2001 13:53:09



Hi,

I am having a problem connecting a client written in perl to a server
written in C. At the accept call I get EINTR error. Can someone help me with
this?

My perl client:

use IO::Socket;
$sock = new IO::Socket::INET ( PeerAddr => 'sun1a',
                               PeerPort =>  5000,
                               Proto    => 'tcp'
                             );

die "Socket could not be created. Reason: $!" unless $sock;

print $sock "msg 1: hi there";
$sock->flush();

print $sock "msg 2: how are you";
$sock->flush();

close ($sock);

The server portion that is giving error. I did not write this. I know this
works as this works with another application.

Retry_accept:

   newsockfd = accept (sockfd, (struct sockaddr *)&client_addr, &addr_len );

    if (newsockfd < 0)
        {
        printf("accept error");
                if (errno == EINTR)
                        goto Retry_accept;
                if(errno != EINTR)
                {
                        close(sockfd);
                        printf("error in accept");
                        exit 1;
                }
        }

    close (sockfd);
    cnt_sock_desk = newsockfd;
    printf("socket id is %d",newsockfd);
    set_tcp_options(cnt_sock_desk);

How can I fix my perl client to work with this. Any help would be greatly
appreciated.

 
 
 

Establishing a socket between a perl client a c server

Post by Nithyanandha » Fri, 08 Jun 2001 22:13:57



> Hi,

> I am having a problem connecting a client written in perl to a server
> written in C. At the accept call I get EINTR error. Can someone help me with
> this?

I don't even look at the perl code(i am a big zero in perl) . But, this is a
general case. EINTR occurs whenever any blocking(like accept())  system call is
interrupted. This error is not a deeply considerable one. So, recall accept( )
till you are connected is the only way.

--Nithyanand,
  Siemens, Bangalore, India.

 
 
 

Establishing a socket between a perl client a c server

Post by anonym.. » Fri, 29 Jun 2001 13:41:38


hard to comment wo seeing the error output from the server,,, are you SURE
client works ??

try
telnet sun1a 5000

instead of your client,,,

also set_tcp_options looks suspect

gje/ky


> Hi,

> I am having a problem connecting a client written in perl to a server
> written in C. At the accept call I get EINTR error. Can someone help me with
> this?

> My perl client:

> use IO::Socket;
> $sock = new IO::Socket::INET ( PeerAddr => 'sun1a',
>                                PeerPort =>  5000,
>                                Proto    => 'tcp'
>                              );

> die "Socket could not be created. Reason: $!" unless $sock;

> print $sock "msg 1: hi there";
> $sock->flush();

> print $sock "msg 2: how are you";
> $sock->flush();

> close ($sock);

> The server portion that is giving error. I did not write this. I know this
> works as this works with another application.

> Retry_accept:

>    newsockfd = accept (sockfd, (struct sockaddr *)&client_addr, &addr_len );

>     if (newsockfd < 0)
>         {
>         printf("accept error");
>                 if (errno == EINTR)
>                         goto Retry_accept;
>                 if(errno != EINTR)
>                 {
>                         close(sockfd);
>                         printf("error in accept");
>                         exit 1;
>                 }
>         }

>     close (sockfd);
>     cnt_sock_desk = newsockfd;
>     printf("socket id is %d",newsockfd);
>     set_tcp_options(cnt_sock_desk);

> How can I fix my perl client to work with this. Any help would be greatly
> appreciated.

 
 
 

1. Making Linux server sockets connect with Borland C++ builder Client Sockets?

Hi there,

I'm starting to work on a Client/Server application that presumably will
work with a server running on Linux, and clients running on either Linux
or on Windows.

I'm testing the "Beginning Linux Programming" examples in a local area
network, and they work fine.   But then I rebooted to Windows NT and
tested a quick silly Borland C++ Builder 4 application, using the
Client Socket control.

I set the properties as follows:

Address:  192.168.0.1   (the address of the machine running the server)
Port:     9734

(port 9734 is the one they use in the example in the book, and is the
port on which the server is listening and accepting connections).

Then, I put an event handler for the "OnConnect" event, just displaying
a Message Box.

When I execute socket->Open(), it crashes!!  (it produces an exception
that I'm not even able to catch -- enclosing the ->Open() in a try
block).

If I run a Linux client exactly as in the book, it does connect.  And
if I set up my Borland C++ Builder client socket to connect to port 119
of news.cyberglobe.net  (the news server of my ISP), it does connect!!!

Does anybody know what am I missing or what am I doing wrong??

Thanks!

Carlos
--
PS: I don't post the Linux server or client code, since it is identical
    to the one in the book -- I assume that it must be the most simple,
    most standard thing.  Let me know if you need to see that code to
    know what's happening.  Thanks.

2. Help please with YDL 2.0 Install

3. Client - Server, Client socket hangs!

4. startup

5. X server: Cannot establish any listening sockets

6. new version of homehttpd

7. Sockets- one server and many clients, how do I name all the clients

8. pc/104 modem problems

9. X server: Cannot establish any listening sockets

10. WHY: the client process has been killed, but the connection on server is still ESTABLISHED

11. How to establish PPPoE server and client in Linux ?

12. Perl: bidir client socket I/O trouble

13. handle more clients by RPC server than socket server