Re: Problem with the send() and recv() in sockets
- From: "Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx>
- Date: Fri, 17 Jun 2005 15:52:59 +0200
To clear you doubts just set sniffer ( better on both machines ) and check
if data sent from driver and received , you
can use windump (http://windump.polito.it - console style UI )
http://winpcap.polito.it ) , ethereal ( www.ethereal.com - GUI ) but you
will need winpcap as packet engine ( http://winpcap.polito.it ) , NetMon of
MSTF
Arkady
"socket_newbee" <socketnewbee@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:096382F1-9326-42AA-B8EB-2DFB99AAABC6@xxxxxxxxxxxxxxxx
>I checked with the Netstat...
>
> The send is Ok...
> Send returns 217 bytes sent ..which is OK ...
> But recv ..It just hangs....No value for nret...No printf ..nothing...I
> doubt if the server is sending me something...
>
> This is the recv part
>
> nret = recv(s, (char *)recbuf, sizeof(recbuf), 0);
>
> printf("recd bytes %d \n", nret);
>
> if(nret == SOCKET_ERROR)
> {
>
> printf("Data receive failed \n");
> return NET_ERROR;
> }
> else
> printf("Data receive OK");
>
>
>
>
> "Arkady Frenkel" wrote:
>
>> Additionally , check with netstat on both peers that you have established
>> connection and check return code from send()/receive() what happen
>> Arkady
>>
>> "Phil Frisbie, Jr." <phil@xxxxxxxxxxxx> wrote in message
>> news:OQUE2FfcFHA.1404@xxxxxxxxxxxxxxxxxxxxxxx
>> > socket_newbee wrote:
>> >
>> >> Hi, My client program does nt communicate with the server....It
>> >> connects
>> >> and then hangs while sending / recv data .....It shows the msg
>> >> connected
>> >> to the server ...Thats it.....I compiled this in VC( VS.NET
>> >> 2003)...there
>> >> are no compilation errors.
>> >
>> > Yes, but you have simple C language errors....
>> >
>> >> Can someone give me some suggestion as to whats wrong with my code
>> >> ?...I
>> >> know that the server is fine and it listens correctly...
>> >>
>> >> Thanks #include <stdio.h> #include <signal.h>
>> >> #include <string.h> #include <stdlib.h> #include <sys/types.h>
>> >> #include
>> >> <windows.h>
>> >> #include <winsock.h>
>> >>
>> >> #pragma comment(lib, "wsock32.lib")
>> >> #define NET_ERROR 1
>> >> #define TRANS_OK 0
>> >>
>> >>
>> >> int main()
>> >> { char *haddr; int n, size, comp, port; char buf[50] =
>> >> "0A111111111110308";
>> >
>> > char buf[] = "0A111111111110308";
>> > This is not really an error, but poor programming.
>> >
>> >> char recbuf[75];
>> >> static int s; static struct sockaddr_in server_addr; /* socket decl
>> >> stuff
>> >> */
>> >>
>> >> WORD sockVersion;
>> >> WSADATA wsaData;
>> >> int nret;
>> >>
>> >> sockVersion = MAKEWORD(1, 1); WSAStartup(sockVersion, &wsaData);
>> >>
>> >> server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr =
>> >> inet_addr("111.111.11.11"); server_addr.sin_port = htons(18965); /*
>> >> create socket */ if(( s = socket(AF_INET, SOCK_STREAM, 0 )) < 0 ) {
>> >> printf("Client : Can't open stream socket\n"); return NET_ERROR; } /*
>> >> connect to server */ if( connect(s, (struct sockaddr *) &server_addr,
>> >> sizeof(server_addr)) < 0) { printf("Client: can't connect to
>> >> server.\n");
>> >> return NET_ERROR;
>> >> } printf("Connected to server ....\n");
>> >>
>> >> nret = send(s, buf, strlen(buf), 0);
>> >
>> > Be careful here! If you really want to send a string, and the code
>> > below
>> > looks like you do, then you also need to send the null termination at
>> > the
>> > end.
>> >
>> > nret = send(s, buf, strlen(buf)+1, 0);
>> >
>> >> if(nret == NET_ERROR)
>> >> {
>> >> printf("Data send failed \n");
>> >> return NET_ERROR; }
>> >>
>> >> /* see what the server sends back to you */
>> >>
>> >> nret = recv(s, recbuf, strlen(recbuf), 0);
>> >
>> > ERROR!
>> > nret = recv(s, recbuf, sizeof(recbuf), 0);
>> >
>> >> printf("%s",recbuf);
>> >>
>> >> closesocket(s); }
>> >
>> > Make sure you fix these things on the server also....
>> >
>> > --
>> > Phil Frisbie, Jr.
>> > Hawk Software
>> > http://www.hawksoft.com
>>
>>
>>
.
- Follow-Ups:
- Re: Problem with the send() and recv() in sockets
- From: socket_newbee
- Re: Problem with the send() and recv() in sockets
- References:
- Problem with the send() and recv() in sockets
- From: socket_newbee
- Re: Problem with the send() and recv() in sockets
- From: Phil Frisbie, Jr.
- Re: Problem with the send() and recv() in sockets
- From: Arkady Frenkel
- Re: Problem with the send() and recv() in sockets
- From: socket_newbee
- Problem with the send() and recv() in sockets
- Prev by Date: Re: How to get the value of a socket's send buffer or recv buffer?
- Next by Date: Re: Convert SOCKET to HANDLE?
- Previous by thread: Re: Problem with the send() and recv() in sockets
- Next by thread: Re: Problem with the send() and recv() in sockets
- Index(es):
Relevant Pages
|