CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2003
    Posts
    82

    HELP:Can connect to server but server didnt receive sent data

    server is using MFC socket class on win2K
    client using sockets on solaris 2.3

    I cant seem to receive anything at Server side coz I put breakpoints in OnReceive() & Receive() of the sock function.

    connection is ok coz server side shows connected IP address n port on the application window, just that no data received.

    This is the CLIENT side

    connectServer(&clientAddr,&sock); //see below

    //fread data from a file to a buffer
    send(sock,buffer,size0f(buffer),0); //


    connectServer(struct sockaddr_in *clientAddr, int *sock)
    {
    arr[1] = "serverPC";

    hp = gethostbyname(arr[1]);

    *sock = socket(AF_INET,SOCK_STREAM,0)
    servAddr.sin_family = AF_INET;
    bcopy(hp->h_addr,&servAddr.sin_addr, hp->h_length);
    servAddr.sin_port = htons(9000);

    result = connect(*sock,&servAddr,sizeof(servAddr) );

    }

    omitted the err checking codes
    any idea where went wrong?
    server side code needed?

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    Yes. Some code of server side might help.
    Check the return value of the send() function on the client side. At least it can show how much data have been placed in the TCP buffer...
    "UNIX is simple; it just takes a genius to understand its simplicity!"

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  4. #4
    Join Date
    Sep 2003
    Posts
    82
    hmmm...
    server side goes like tis

    Server.Create(9000,SOCK_STREAM,myIP);
    Server.Listen();

    CSock::OnAccept(int nErrorCode)
    {
    Accept(socket,0,0)
    .......
    }

    void CSock::OnReceive(int nErrorCode)
    {

    // TODO: Add your specialized code here and/or call the base class

    long dataLength;
    Receive(&dataLength, 4);

    if (dataLength > 0&& dataLength < 100000) //Just to make sure the client doesn't crash the server)
    {
    byte* message = new byte[dataLength+1];

    int nRec = Receive(message,dataLength);
    message[nRec] = '\0';

    //::SendMessage(hParent,WM_RECEIVE_MESSAGE,(WPARAM)message,(LPARAM)nSocket);
    }

    CSocket::OnReceive(nErrorCode);
    }

  5. #5
    Join Date
    Sep 2003
    Posts
    82
    attached the server n client code

    anyone...?
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2003
    Posts
    82
    I just need to implement a listening socket that can accept and receive data.

    Anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured