Socket port destination problem

Hi everybody,

I have an application where two different socket connections run in order to communicate with a machine. Over the first one (UDP) I send a request packet to ask for data and over the other one connection (TCP) I receive the data.
I repeat this procedure two times that is, I request a block of data and when it's finished I request a second one.By the first time it works without problems but by the second time I discovered with wireshark that the request packet is sent to another port (not over the original port). I know I haven't made changes between the first request call and the second one because I have a function where I initialize all connections at the beginning and it works for the first transmission.

Can anyone help me?

Thank you very much
Why are you using UDP? Use TCP both ways.

That should (hopefully) fix your problem.
Hi,

because that is design requirements...

Hi again,

Now I can describe the problem better

I have a tcp server that wait for data in the recv function after accept. I receive data buffer of 1500 bytes but I don't receive only one buffer. I receive more. The first time the socket receives something port=2000 (so it's right) but the second time and successively port=49154. Something is wrong with the receive function...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
AcceptSocket = accept(socketInTCP, NULL, NULL);		 
		 if (AcceptSocket == INVALID_SOCKET)
		 {	 
			
			 printf("Server: WSA:\n");
			
		 }
		 else
		 {   
			 printf("Server: Client Connected!\n");
			 //Receive Packages from Client
			 while(run_tcpserver)
			 {  	bytesRecv = recv(AcceptSocket, recvbuf, sizeof(recvbuf), 0);
				if (bytesRecv > 0)
				{if(ctr1==1)
					{	
						WaitForSingleObject(mutex_req,INFINITE);
						//The first time it receives port = 2000
					}
				 
                                 //the second time and successively port =49154
                                 ctr1=0;
				 ofstream outfile(outputfile, ios::out |ios::ate | ios::binary);//open
				 rcv_data=rcv_data+bytesRecv;
				 cout << "\xd" << rcv_data;
				 
				 outfile.write (var, sizeof(var));
				 outfile.close();
				 memset(recvbuf,0,sizeof(recvbuf));
				 
                                 if(rcv_data==(length_dummy*4))
					{
						ReleaseMutex(mutex_req);
						
					}


have anyone any ideas??
I think it's a synchronization problem because I use a mutex for the screen and I think something is wrong but I can't see it....
Topic archived. No new replies allowed.