Socket programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sritejv
    New Member
    • Mar 2008
    • 9

    Socket programming

    Hi,
    I a reading line by line from a file and sending it over a TCP connection to a destination.

    However at the receiver i a m receiving multiple lines because of the extra space in the buffer.

    SENDER:
    while(fgets(nam e,70,fp)!=NULL) //sending one line at a time
    {
    printf("%s frame sent\n",name);
    c=send(s,name,s trlen(name),0);
    }

    AT THE RECEIVER:
    .
    .
    .
    len=recv(i,buf, 70,0);(keeps looping as long as there is data to be received)

    I am receiving multiple lines at the same time due to the excess buffer capacity.

    How do i receive what is been sent at a time?

    Sritej
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    have you used select on the receiver end before reading from the socket.?

    Raghuram

    Comment

    • sritejv
      New Member
      • Mar 2008
      • 9

      #3
      Yes i Have used select.(but no issues there it works fine).but i have solved the problem
      this is my new 'send'
      c=send(s,name,s trlen(name)+1,0 );
      (my friend suggest the +1 after the strlen.i dontknow why it worked.

      can someone please explain?

      Comment

      Working...