Re: Problem with the send() and recv() in sockets

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
>>
>>
>>


.



Relevant Pages

  • Re: SubSeven alerts: Norton Firewall vs Hacks/Trojan cleaner
    ... Personal Web Server -- PWS), mail servers, news servers, ftp servers, IRC ... | - use netstat with appropriate options to check for listening services ... firewall which make decisions as to what to ... As for the Subseven Alerts, again, Wolfgang is largely correct; ...
    (comp.security.firewalls)
  • Re: Wnidows Server 2003 - I need help in getting the Connection Co
    ... command if already running. ... it fires off the netstat command for you, sending the results from that to ... SHELL EXEC FUNCTION ON SERVER 2003 - PERMISION PROBLEM!!!!! ... requires administator access we are get file permison problems - ANY ...
    (microsoft.public.windowsmedia.server)
  • Re: Slow Box
    ... server, any scripts on the web site? ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ... For lsof and netstat, there are too many lines to paste. ...
    (comp.os.linux.misc)
  • Re: SQL Server does not exist or access denied.
    ... netstat -noa shows a bunch of local local processes, ... Dumb question first: The server is running? ... Look for the process ID of the server process in task manager. ... not being able to connect with port 1443. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Wnidows Server 2003 - I need help in getting the Connection Co
    ... exteral application in since it needs to run on Windows Server 2003. ... command if already running. ... it fires off the netstat command for you, sending the results from that to ... SHELL EXEC FUNCTION ON SERVER 2003 - PERMISION PROBLEM!!!!! ...
    (microsoft.public.windowsmedia.server)