|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I was writing a perl program that acts as a server opening a port and receiving connections from clients written in C.
The C clients gets connected successfully but when they send data the server do nothing. Well, due my problem I wrote a perl client and I sent the same data, but this time, the server shows the previous data from the C client and from the perl client. Only after sent a data from a perl program the server shows the data sent by the C program. Any ideas? muy malo mi ingles :S |
|
|||
|
You probably want to set $| to non-zero. See $OUTPUT_AUTOFLUSH in man perlvar.
|
|
|||
|
Thank you for the fast reply.
I did what you said, but nothing good happens. :S Finally I wrote a perl server, again, but using the oop interface provided by IO::Socket::INET package. This ways works fine but I can't use it because I need a low level control, then, trying more I found... This way does not work, even if I autoflush() the STDOUT. The data just stay buffered until the client gets disconnected. Code:
sub load_socket()
{
****socket(SERVER,PF_INET,SOCK_STREAM,getprotobyname($config{protocol}));
****my $my_address = sockaddr_in($config{port},INADDR_ANY); #(INADDR_ANY)any address because i am the server
****setsockopt(SERVER,SOL_SOCKET, SO_REUSEADDR,1);
****bind(SERVER,$my_address) || die "Can't bind ($!)"; #register the socket ********
****listen(SERVER,10) || die "Can't listen ($!)";****
****while (my $client_addr = accept(CLIENT,SERVER))
****{
********my($port, $packed_ip) = sockaddr_in($client_addr);
********my $ip = inet_ntoa($packed_ip);
********print "Client Connected->'$ip'\n";
********#my $out = <CLIENT>;
********print <CLIENT>;
****}****
****close (SERVER);
}
Rare:S Code:
sub load_socket()
{
****socket(SERVER,PF_INET,SOCK_STREAM,getprotobyname($config{protocol}));
****my $my_address = sockaddr_in($config{port},INADDR_ANY); #(INADDR_ANY)any address because i am the server
****setsockopt(SERVER,SOL_SOCKET, SO_REUSEADDR,1);
****bind(SERVER,$my_address) || die "Can't bind ($!)"; #register the socket ********
****listen(SERVER,10) || die "Can't listen ($!)";****
****while (my $client_addr = accept(CLIENT,SERVER))
****{
********my($port, $packed_ip) = sockaddr_in($client_addr);
********my $ip = inet_ntoa($packed_ip);
********print "Client Connected->'$ip'\n";
********my $out = <CLIENT>; #set to a var first
********print $out;
****}****
****close (SERVER);
}
|
|
|||
|
You should also check the value of $/ aka $INPUT_RECORD_SEPARATOR for the CLIENT FD. Also it's the CLIENT FD you have to autoflush, not stdout.
|
|
|||
|
yes, I understand, I already autoflush the client, before calling the sub, however, the output stills buffered.
Another rare thing: only if I concat a /r/n or /n to the data (to send) I receive it. The program is full of problems. My client (C++) runs over an AS400 and I need to convert the EDBDIC string to ASCII string. :S |
|
|||
|
You should use wireshark to look at the packets arriving to see whether the client is sending everything. Maybe there is something data still unsent by the client and it's not the server's fault, especially as you say appending an end-of-line fixes the problem. You did not say before that you were not sending from a different OS. You have to look at the conventions of that OS. If you are programming in stdio did you flush the stream after writing to the network?
|
|
|||
|
Quote:
Quote:
When the "buffer thing" happens the program never returns me the control after calling the send() function of the socket API. Tomorrow (because now is midnight here in Paraguay ) I'll sniffer the communication between the client and the server.Thank you! |
|
|||
|
I don't know about Perl, but when reading from the sockets in C, you have to read multiple times, until there is nothing left in the incoming buffer. I don't know if in Perl <CLIENT> buffers the input first, or returns what is immediately in it. Also how big is this data? If the packets are very, very small and Nagle algorithm is engaged on the client side (TCP_DELAY), you won't see anything on the server until it accumulates a bit. |
|
|||
|
Just realized this: Quote:
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|