Re: sockets

From: ZoombyWoof (zoombywoofremove_at_thishotmail.com)
Date: 07/07/04


Date: Wed, 07 Jul 2004 10:54:34 +0200

Sam wrote:

> Hi guys, Just a problem with sockets
>
>
> I've done a little C client/server
>
>
> Server side, "classic" :
>
>
> ...
> while (true)
> {
> sd_client = accept(sd,(struct sockaddr *)&cin,&addrlen);
>
> n = recv(sd_client,buffer,sizeof(buffer),0);
>
> buffer[n]=0;
> printf("from cli : %s\n", buffer);
>
>
> sprintf(buffer, "ok %d\n", j++);
> if (send(sd_client,buffer,strlen(buffer),0) == -1)
> {
> perror("send");
> exit(1);
> }
>
> close (sd_client);
> }
>
>
>
> But now, when I try to connect to the client:
>
>
> First connection works perfectly (server receives my stream)
>
> n = send(sd, "hello",strlen("hello"),0);
> n = recv(sd, buffer, bufsize,0);
> buffer[n]=0;
> printf ("from srv : %s\n",buffer);
>
> Now, after that, if I try (again)
>
> n = send(sd, "test 2",strlen("test 2"),0);
> n = recv(sd, buffer, bufsize,0);
> buffer[n]=0;
> printf ("from srv : %s\n",buffer);
>
> This time server doesn't receive datas at all ???
>
> Where is my mistake ?
Your server closes the socket after the first message is received.
 From the code you provided the client does NOT open a new connection
before the second message is sent to the server. Skip the close (sd_client)
in your server loop if you dont make a new connection before the second
call in the client.

/ZW



Relevant Pages

  • Re: .Net Scalability problem
    ... LoadRunner will peak out a server with a few virtual users. ... To get an idea of load, ... Fire off the test client and watch the number of ... > So I think that the MTC generate concurrent connection and per ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connection lost at same time every hour (sometimes)
    ... After making the two following alterations on the server the problem seems ... After analyze your ipconfig on SBS and client, ... Then, other connection is good, ...
    (microsoft.public.windows.server.sbs)
  • Re: server disconnection - very often
    ... Reason of permanent popups is VMware server aplication on clients. ... Run CEICW to configure the network of SBS: ... Two network adapters - manual router connection to broadband ... Uninstall VMware on client. ...
    (microsoft.public.windows.server.sbs)
  • Re: Lan setup 2 nic
    ... The external nic only has TCP/IP enabled. ... Ipconfig of the server is looking good, but the client is still missing the ... > connection so we have a 2 nic with router setup now. ...
    (microsoft.public.windows.server.sbs)
  • Re: Regular disconnections from remote web workplace
    ... I can connect to office server and all office clients from home at all times ... be physically working right up until the connection is lost. ... If I enter http://companyip from a client I receive the login screen for the ... Click Services tab and select Hide All Microsoft Services and Disable ...
    (microsoft.public.windows.server.sbs)