Send UDP packet From Server to Client over internet

Joined
Aug 9, 2009
Messages
1
Reaction score
0
Dear all

i have a server with an valid ip, a programe is runnig on the server that can recived udp packets
gps send data to this server by gprs

at first gps send login request i succcessfully get that but i can't response to gps

i developed a programe to test it , this programe send udp packet to server from a pc whit shared ip but i can't send a packet to this pc by server

the programe work on local network well and i can send and recived packets , but i don't know how can i send packet to a shared ip address


at below are some code i used:


Code:
[color=blue]protected[/color] UdpClient receivingUdpClient;
 
		[color=blue]protected[/color] System.Threading.Thread ThreadReceive;
 
		[color=blue]public[/color] System.Net.IPEndPoint RemoteIpEndPoint= [color=blue]new[/color] System.Net.IPEndPoint(System.Net.IPAddress.Any,0);
 
		 [color=blue]private[/color] [color=blue]void[/color] button1_Click([color=blue]object[/color] sender, EventArgs e) 
		{ 
		 [color=blue]try[/color]{ 
				SocketNO = Convert.ToInt32( textBox1.Text); 
				receivingUdpClient = [color=blue]new[/color] UdpClient(SocketNO); 
				ThreadReceive = [color=blue]new[/color] System.Threading.Thread(ReceiveMessages);
 
				ThreadReceive.Start(); 
			}			[color=blue]catch[/color](Exception X) 
			{ 
				MessageBox.Show(X.Message); 
			} 
		}
 
		[color=blue]public[/color] [color=blue]void[/color] ReceiveMessages() 
		{ 
			[color=blue]try[/color]{ 
				[color=blue]byte[/color][] receiveBytes = receivingUdpClient.Receive([color=blue]ref[/color] RemoteIpEndPoint); 
				[color=blue]string[/color] strReturnData = System.Text.Encoding.Unicode.GetString(receiveBytes);  
				textBox2.Text = textBox2.Text + Environment.NewLine + [color=#a31515]"The message received is \"[/color]"; 
				textBox2.Text = textBox2.Text + Encoding.ASCII.GetString(receiveBytes) + [color=#a31515]"\"[/color]"; 
				textBox2.Text += Environment.NewLine + Environment.NewLine; 
				[color=blue]if[/color] (receiveBytes[0] == 0x29 && receiveBytes[1] == 0x29 && receiveBytes[2] == 0xB1) 
				{ 
				 [color=blue]byte[/color][] SentReply = SendReplyPacket(receiveBytes, RemoteIpEndPoint.Address); 
				 receivingUdpClient.Send(SentReply, SentReply.Length, RemoteIpEndPoint); 	  
  [color=green]// here how can i send packet to shared ip address [/color] 
				} 
			 } 
			[color=blue]catch[/color](Exception X) 
			{ 
				Console.WriteLine(X.Message); 
			} 
		}
 
Last edited:
Back
Top