LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 06-18-2009, 03:36 AM   #1
alfred2g
LQ Newbie
 
Registered: May 2009
Posts: 6

Rep: Reputation: 0
Unhappy tcp connection problem


hi

i wrote a program(in C) that connects to a server
(the server uses a java program)
and receive info from it
the program uses a simple send and recv function calls
and parses the data of course
the receive is timing out all the time as if the server is not sending anything back

from the server terminal my message is received
and it shows that the server is sending back a message
but i am not receiving it


int send_frame(int sock ,char* buffer, int size)
{
int sent;
int length=0;

while(size > 0 ){
sent = send(sock, buffer + length, size-length, 0);
if(sent ==-1){
return ERROR_SEND_SOCKET;
}else if(sent == 0){
return WARN_CONNECTION_CLOSED;
}
size-=sent;
length = length + sent;
}
printf("frame send to client %d\n", sock);
return SUCCESS;
}


int read_frame(int client, char* buffer, int size, int timeout)
{
int rVal;
fd_set set;
struct timeval tv;
int length = 0;

FD_ZERO(&set);
FD_SET(client, &set);

tv.tv_sec = timeout;
tv.tv_usec= 0;
printf("waiting for a message ...on socket %d\n", client);
if((rVal = select(client+1, &set, NULL, NULL, &tv))==-1){
return ERROR_READING_SOCKET;
}else if(rVal == 0){ /* nothing to read */
return ERROR_CONNECTION_TIMEOUT;
}
if(FD_ISSET(client , &set)){
if(fcntl(client , F_SETFL, O_NONBLOCK)==-1){
return ERROR_READING_SOCKET;
}
}else{
return ERROR_CONNECTION_TIMEOUT2;
}

//while(length < size){

rVal = recv(client, buffer+length, size-length, 0/*MSG_DONTWAIT*/);

if(rVal == -1){
return ERROR_READING_SOCKET;
}else if(rVal ==0){
return WARN_CONNECTION_CLOSED;
}else{
length = length + rVal;
}
//}
buffer[length] = '\0';
return SUCCESS;
}

but when i imitate the program using telnet the server responds back normally

i also created a simple server simulation and it works fine(my program is sending and receiving messages)

what could the problem be?? a firewall configuration?? Selinux ??

please help me

thanks in advance
alfred gedeon

Last edited by alfred2g; 06-18-2009 at 03:50 AM.
 
Old 06-18-2009, 03:54 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
Could be a number of things. Shut off the firewall, turn off selinux, and use tcpdump to name a few.

-twantrd
 
Old 06-21-2009, 09:16 AM   #3
alfred2g
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by twantrd View Post
Could be a number of things. Shut off the firewall, turn off selinux, and use tcpdump to name a few.

-twantrd
i turned off the firewall and selinux
and tcpdump shows the response from the server
but i still can't read the data
 
Old 06-23-2009, 05:05 AM   #4
alfred2g
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
here is the result of a tcpdump and it shows checksum error
what could be the problem??
on the test machines it works fine with all the checksums are correct

$ tcpdump -r /home/smartech/Desktop/test2.txt -s0 -vvv -XX
reading from file /home/smartech/Desktop/test2.txt, link-type EN10MB (Ethernet)
13:57:40.253650 IP (tos 0x0, ttl 64, id 27341, offset 0, flags [DF], proto TCP (6), length 60) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: S, cksum 0x7355 (correct), 2827321921:2827321921(0) win 5840 <mss 1460,sackOK,timestamp 2229463180 0,nop,wscale 7>
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 003c 6acd 4000 4006 b76c 0a05 0241 0a06 .<j.@.@..l...A..
0x0020: 0237 de3c 2ee5 a885 8241 0000 0000 a002 .7.<.....A......
0x0030: 16d0 7355 0000 0204 05b4 0402 080a 84e2 ..sU............
0x0040: e88c 0000 0000 0103 0307 ..........
13:57:40.254127 IP (tos 0x0, ttl 128, id 25107, offset 0, flags [none], proto TCP (6), length 64) 10.6.2.55.dbisamserver1 > 10.5.2.65.56892: S, cksum 0x5431 (correct), 2612508059:2612508059(0) ack 2827321922 win 16384 <mss 1460,nop,wscale 0,nop,nop,timestamp 0 0,nop,nop,sackOK>
0x0000: 0017 a41d 86da 000e 8323 6f00 0800 4500 .........#o...E.
0x0010: 0040 6213 0000 8006 c022 0a06 0237 0a05 .@b......"...7..
0x0020: 0241 2ee5 de3c 9bb7 b59b a885 8242 b012 .A...<.......B..
0x0030: 4000 5431 0000 0204 05b4 0103 0300 0101 @.T1............
0x0040: 080a 0000 0000 0000 0000 0101 0402 ..............
13:57:40.254152 IP (tos 0x0, ttl 64, id 27342, offset 0, flags [DF], proto TCP (6), length 52) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: ., cksum 0x675e (correct), 1:1(0) ack 1 win 46 <nop,nop,timestamp 2229463181 0>
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 0034 6ace 4000 4006 b773 0a05 0241 0a06 .4j.@.@..s...A..
0x0020: 0237 de3c 2ee5 a885 8242 9bb7 b59c 8010 .7.<.....B......
0x0030: 002e 675e 0000 0101 080a 84e2 e88d 0000 ..g^............
0x0040: 0000 ..
13:57:40.254221 IP (tos 0x0, ttl 64, id 27343, offset 0, flags [DF], proto TCP (6), length 285) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: P, cksum 0x1992 (incorrect (-> 0x6193), 1:234(233) ack 1 win 46 <nop,nop,timestamp 2229463181 0>
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 011d 6acf 4000 4006 b689 0a05 0241 0a06 ..j.@.@......A..
0x0020: 0237 de3c 2ee5 a885 8242 9bb7 b59c 8018 .7.<.....B......
0x0030: 002e 1992 0000 0101 080a 84e2 e88d 0000 ................
0x0040: 0000 3c3f 786d 6c20 7665 7273 696f 6e3d ..<?xml.version=
0x0050: 2231 2e30 2220 656e 636f 6469 6e67 203d "1.0".encoding.=
0x0060: 2275 7466 2d38 223f 3e3c 6d65 7373 6167 "utf-8"?><messag
0x0070: 6520 6170 7020 3d20 224d 4641 2220 7479 e.app.=."MFA".ty
0x0080: 7065 203d 224e 223e 3c72 6566 6964 3e30 pe.="N"><refid>0
0x0090: 3030 3030 3030 3031 623c 2f72 6566 6964 00000001b</refid
0x00a0: 3e3c 6d6f 6269 6c65 7320 6e70 6920 3d22 ><mobiles.npi.="
0x00b0: 3122 3e3c 6974 3e3c 6e6f 3e39 3636 3530 1"><it><no>96650
0x00c0: 3030 3237 3039 383c 2f6e 6f3e 3c74 6578 0027098</no><tex
0x00d0: 7420 6c61 6e67 3d22 656e 223e 4465 6172 t.lang="en">Dear
0x00e0: 2043 7573 746f 6d65 722c 2079 6f75 7220 .Customer,.your.
0x00f0: 7061 7373 776f 7264 2069 733a 203c 2f74 password.is:.</t
0x0100: 6578 743e 3c63 7074 3e31 3233 3c2f 6370 ext><cpt>123</cp
0x0110: 743e 3c2f 6974 3e3c 2f6d 6f62 696c 6573 t></it></mobiles
0x0120: 3e3c 2f6d 6573 7361 6765 3e ></message>
13:57:40.418656 IP (tos 0x0, ttl 128, id 25109, offset 0, flags [DF], proto TCP (6), length 52) 10.6.2.55.dbisamserver1 > 10.5.2.65.56892: ., cksum 0x84da (correct), 1:1(0) ack 234 win 65302 <nop,nop,timestamp 48422863 2229463181>
0x0000: 0017 a41d 86da 000e 8323 6f00 0800 4500 .........#o...E.
0x0010: 0034 6215 4000 8006 802c 0a06 0237 0a05 .4b.@....,...7..
0x0020: 0241 2ee5 de3c 9bb7 b59c a885 832b 8010 .A...<.......+..
0x0030: ff16 84da 0000 0101 080a 02e2 dfcf 84e2 ................
0x0040: e88d ..
13:59:54.385673 IP (tos 0x0, ttl 64, id 27344, offset 0, flags [DF], proto TCP (6), length 52) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: F, cksum 0x77b1 (correct), 234:234(0) ack 1 win 46 <nop,nop,timestamp 2229597340 48422863>
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 0034 6ad0 4000 4006 b771 0a05 0241 0a06 .4j.@.@..q...A..
0x0020: 0237 de3c 2ee5 a885 832b 9bb7 b59c 8011 .7.<.....+......
0x0030: 002e 77b1 0000 0101 080a 84e4 f49c 02e2 ..w.............
0x0040: dfcf ..
13:59:54.385927 IP (tos 0x0, ttl 128, id 27668, offset 0, flags [DF], proto TCP (6), length 52) 10.6.2.55.dbisamserver1 > 10.5.2.65.56892: ., cksum 0x738d (correct), 1:1(0) ack 235 win 65302 <nop,nop,timestamp 48424202 2229597340>
0x0000: 0017 a41d 86da 000e 8323 6f00 0800 4500 .........#o...E.
0x0010: 0034 6c14 4000 8006 762d 0a06 0237 0a05 .4l.@...v-...7..
0x0020: 0241 2ee5 de3c 9bb7 b59c a885 832c 8010 .A...<.......,..
0x0030: ff16 738d 0000 0101 080a 02e2 e50a 84e4 ..s.............
0x0040: f49c ..
13:59:54.404718 IP (tos 0x0, ttl 128, id 27710, offset 0, flags [DF], proto TCP (6), length 164) 10.6.2.55.dbisamserver1 > 10.5.2.65.56892: P, cksum 0xfb5e (correct), 1:113(112) ack 235 win 65302 <nop,nop,timestamp 48424202 2229597340>
0x0000: 0017 a41d 86da 000e 8323 6f00 0800 4500 .........#o...E.
0x0010: 00a4 6c3e 4000 8006 7593 0a06 0237 0a05 ..l>@...u....7..
0x0020: 0241 2ee5 de3c 9bb7 b59c a885 832c 8018 .A...<.......,..
0x0030: ff16 fb5e 0000 0101 080a 02e2 e50a 84e4 ...^............
0x0040: f49c 3c6d 6573 7361 6765 2061 7070 3d22 ..<message.app="
0x0050: 4d46 4122 2074 7970 653d 224e 223e 0d0a MFA".type="N">..
0x0060: 2020 3c72 6566 6964 3e30 3030 3030 3030 ..<refid>0000000
0x0070: 3031 623c 2f72 6566 6964 3e0d 0a20 203c 01b</refid>....<
0x0080: 6572 726f 7220 636f 6465 3d22 3030 3030 error.code="0000
0x0090: 223e 5375 6363 6573 7366 756c 3c2f 6572 ">Successful</er
0x00a0: 726f 723e 0d0a 3c2f 6d65 7373 6167 653e ror>..</message>
0x00b0: 0d0a ..
13:59:54.404818 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 40) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: R, cksum 0x5e8a (correct), 2827322156:2827322156(0) win 0
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 0028 0000 4000 4006 224e 0a05 0241 0a06 .(..@.@."N...A..
0x0020: 0237 de3c 2ee5 a885 832c 0000 0000 5004 .7.<.....,....P.
0x0030: 0000 5e8a 0000 ..^...
13:59:54.404835 IP (tos 0x0, ttl 128, id 27711, offset 0, flags [DF], proto TCP (6), length 52) 10.6.2.55.dbisamserver1 > 10.5.2.65.56892: F, cksum 0x731c (correct), 113:113(0) ack 235 win 65302 <nop,nop,timestamp 48424202 2229597340>
0x0000: 0017 a41d 86da 000e 8323 6f00 0800 4500 .........#o...E.
0x0010: 0034 6c3f 4000 8006 7602 0a06 0237 0a05 .4l?@...v....7..
0x0020: 0241 2ee5 de3c 9bb7 b60c a885 832c 8011 .A...<.......,..
0x0030: ff16 731c 0000 0101 080a 02e2 e50a 84e4 ..s.............
0x0040: f49c ..
13:59:54.404843 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 40) 10.5.2.65.56892 > 10.6.2.55.dbisamserver1: R, cksum 0x5e8a (correct), 2827322156:2827322156(0) win 0
0x0000: 000e 8323 6f00 0017 a41d 86da 0800 4500 ...#o.........E.
0x0010: 0028 0000 4000 4006 224e 0a05 0241 0a06 .(..@.@."N...A..
0x0020: 0237 de3c 2ee5 a885 832c 0000 0000 5004 .7.<.....,....P.
0x0030: 0000 5e8a 0000


thanks

Last edited by alfred2g; 06-23-2009 at 07:36 AM.
 
Old 06-24-2009, 11:13 AM   #5
alfred2g
LQ Newbie
 
Registered: May 2009
Posts: 6

Original Poster
Rep: Reputation: 0
hi
i solved the problem
the java server (which i did not write)was expecting and CR LF at the end of the input
thats why telnet was working and none of my tests

thnaks again
 
  


Reply

Tags
connection, receive, socket, tcp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
log for TCP/IP (TCP) connection? fireball003 Linux - Server 4 12-04-2008 01:58 PM
how do i kill a tcp connection sunlinux Linux - Security 1 08-24-2007 07:33 AM
hijacking tcp connection atul_mehrotra Linux - Networking 4 04-30-2005 12:50 AM
Interesting TCP/IP Problem? PosgreSQL and Internet Connection Sharing Don't Work iaypaa Linux - Networking 3 11-04-2002 05:23 AM
Unable to get TCP/IP connection kgunnar Linux - Newbie 9 05-01-2002 04:24 AM


All times are GMT -5. The time now is 09:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration