| |

VerySource

 Forgot password?
 Register
Search
View: 1239|Reply: 13

Please network programming experts come to advise !!!!!!!!!

[Copy link]

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-15 16:00:01
| Show all posts |Read mode
Beginner network programming, not enough grasp of tcp transmission of socket,
E.g:
Three packets are sent in sequence on the server 1-> 2-> 3, and 3-> 1-> 2 are received out of order on the client.
For another example, recv (s, buffer, 1024, 0) is specified to take 1024 bytes from the buffer.
Please master to get lost, not grateful !!!
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-16 01:30:01
| Show all posts
The first puzzle can describe how you sent it? I am also a little puzzled


The second puzzle for you is caused by sticky packets, which is normal for tcp
Reply

Use magic Report

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-16 11:45:01
| Show all posts
The cause of the first problem is the direct use of 3 send functions,
I do n’t know if this is the case when the three packages are combined into a send.
Reply

Use magic Report

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-16 12:30:01
| Show all posts
The above is my wild guess, the second case can basically be handled by itself, but if there is a mess in the order of the packets, I do n’t know how to deal with it.
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-16 13:45:01
| Show all posts
Oh, this is not the case with tcp

On the server side, three packets are sent in sequence 1-> 2-> 3, while on the client side, 3-> 1-> 2 is received out of order.
Reply

Use magic Report

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-16 15:00:01
| Show all posts
This is not the first time, it has been a long time.
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-16 17:30:01
| Show all posts
What about the program? Post it, including the creation of the socket
Reply

Use magic Report

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-16 21:30:02
| Show all posts
The server is VB, use socket control
   Dim r1 (1023) As Byte
   Dim r2 (1023) As Byte
   
   Dim r3 (487) As Byte

   m_DeviceSocket.SendData r1
   m_DeviceSocket.SendData r2
   m_DeviceSocket.SendData r3

Client C ++
           #define MaxRecv 1024
           SOCKET serverSocket;
           serverSocket = NULL;

sockaddr_in m_addr;
The
WORD version = MAKEWORD (2,0);
WSADATA wsadata;
WSAStartup (version,&wsadata);

serverSocket = socket (AF_INET, SOCK_STREAM, 0);
           m_addr.sin_family = AF_INET;
m_addr.sin_addr.S_un.S_addr = inet_addr ((char *) "192.168.1.243");
m_addr.sin_port = htons (12343);

connect (serverSocket, (LPSOCKADDR)&m_addr, sizeof (m_addr));

           CHAR recvStr [MaxRecv];
 
long reclen = 0;

           while (1) {
memset (recvStr, 0, sizeof (recvStr));
reclen = recv (serverSocket, recvStr, sizeof (recvStr), 0);
           }
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-17 11:15:01
| Show all posts
m_DeviceSocket.SendData r1
DoEvent
m_DeviceSocket.SendData r2
DoEvent
m_DeviceSocket.SendData r3
DoEvent

Look at
Reply

Use magic Report

1

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-17 14:30:02
| Show all posts
The vb socket is not sent immediately, doevent is useless,
 function aa ()
   Dim r1 (1023) As Byte
   Dim r2 (1023) As Byte
   
   Dim r3 (487) As Byte

   m_DeviceSocket.SendData r1
   m_DeviceSocket.SendData r2
   m_DeviceSocket.SendData r3

end function
In VB, you must wait for the end function before sending it together. Microsoft's packaged socket should not have this situation.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list