This is probably more of a networking question than a Python one, but
it would be nice to know if someone has done this with Python's socket
module. And besides one usually gets more information from c.l.py than
anywhere else :)
I have a server with a static "public" IP and a client behind a NAT. I
would like to send UDP packets from the server to the client. So what I
need to do is open up a "hole" in the NAT and let the server know the
target IP and port of the client where it can send its packets.
Now I have read somewhere that you can have TCP and UDP running on the
same port. Not sure if this is true. Would it be a reasonable solution
to initiate a TCP connection from the client to the server and somehow
(?) let the server figure out how the client is connecting? And then
send UDP to client over the same (IP, port)? 12 5736
Janto Dreijer a écrit :
This is probably more of a networking question than a Python one, but
it would be nice to know if someone has done this with Python's socket
module. And besides one usually gets more information from c.l.py than
anywhere else :)
I have a server with a static "public" IP and a client behind a NAT. I
would like to send UDP packets from the server to the client. So what I
need to do is open up a "hole" in the NAT and let the server know the
target IP and port of the client where it can send its packets.
Now I have read somewhere that you can have TCP and UDP running on the
same port. Not sure if this is true. Would it be a reasonable solution
to initiate a TCP connection from the client to the server and somehow
(?) let the server figure out how the client is connecting? And then
send UDP to client over the same (IP, port)?
Initiate an UDP connection from the client to the server and have the
server send back the UDP packets to the address you get in the
"recvfrom" result.
Awesome! I haven't tested it on the actual server but I think it works.
Thanks!
I prefer a TCP connection solution and will post one if it works.
server.py
========
from socket import *
print "listening"
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind((" localhost", 1234)) # visibility to outside world
payload, addr = UDPSock.recvfro m(1024)
print "message from %s: %s" % (`addr`, payload)
UDPSock = socket(AF_INET, SOCK_DGRAM) # open UDP socket
result = UDPSock.sendto( "your public address is %s" % `addr`, addr)
client.py
=====
from socket import *
UDPSock = socket(AF_INET, SOCK_DGRAM) # open UDP socket
result = UDPSock.sendto( "what's my public address?", ("localhost" ,
1234))
payload, addr = UDPSock.recvfro m(1024)
print payload
results:
====
listening
message from ('127.0.0.1', 32787): what's my public address?
your public address is ('127.0.0.1', 32787)
On 2006-09-15, Christophe <ch************ *@free.frwrote:
Initiate an UDP connection from the client to the server and
have the server send back the UDP packets to the address you
get in the "recvfrom" result.
There's no such thing as a "UDP connection", so I don't
understand what you're suggesting.
--
Grant Edwards grante Yow! By MEER biz doo
at SCHOIN...
visi.com
On 2006-09-15, Janto Dreijer <ja****@gmail.c omwrote:
I have a server with a static "public" IP and a client behind a NAT. I
would like to send UDP packets from the server to the client. So what I
need to do is open up a "hole" in the NAT and let the server know the
target IP and port of the client where it can send its packets.
Now I have read somewhere that you can have TCP and UDP running on the
same port.
True.
Not sure if this is true.
It is.
Would it be a reasonable solution to initiate a TCP connection
from the client to the server and somehow (?) let the server
figure out how the client is connecting? And then send UDP to
client over the same (IP, port)?
I doubt that will work unless the firewall has been
specifically designed to recognize that pattern of activity and
allow the incoming UDP packets. I don't think most firewall
have default rules that allow UDP packets to tunnel back along
a TCP connection.
--
Grant Edwards grante Yow! Clear the
at laundromat!! This
visi.com whirl-o-matic just had a
nuclear meltdown!!
Oops. That second UDPSock = socket(...) in the server.py shouldn't be
there.
Janto Dreijer wrote:
Awesome! I haven't tested it on the actual server but I think it works.
Thanks!
I prefer a TCP connection solution and will post one if it works.
server.py
========
from socket import *
print "listening"
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind((" localhost", 1234)) # visibility to outside world
payload, addr = UDPSock.recvfro m(1024)
print "message from %s: %s" % (`addr`, payload)
UDPSock = socket(AF_INET, SOCK_DGRAM) # open UDP socket
result = UDPSock.sendto( "your public address is %s" % `addr`, addr)
client.py
=====
from socket import *
UDPSock = socket(AF_INET, SOCK_DGRAM) # open UDP socket
result = UDPSock.sendto( "what's my public address?", ("localhost" ,
1234))
payload, addr = UDPSock.recvfro m(1024)
print payload
results:
====
listening
message from ('127.0.0.1', 32787): what's my public address?
your public address is ('127.0.0.1', 32787)
Grant Edwards wrote:
On 2006-09-15, Christophe <ch************ *@free.frwrote:
Initiate an UDP connection from the client to the server and
have the server send back the UDP packets to the address you
get in the "recvfrom" result.
There's no such thing as a "UDP connection", so I don't
understand what you're suggesting.
I think he means "connection " as in "associated ip/port". Which
actually does work, as I've posted.
Grant Edwards wrote:
On 2006-09-15, Janto Dreijer <ja****@gmail.c omwrote:
....
Would it be a reasonable solution to initiate a TCP connection
from the client to the server and somehow (?) let the server
figure out how the client is connecting? And then send UDP to
client over the same (IP, port)?
I doubt that will work unless the firewall has been
specifically designed to recognize that pattern of activity and
allow the incoming UDP packets. I don't think most firewall
have default rules that allow UDP packets to tunnel back along
a TCP connection.
Thanks for the info!
I think you may be right. I had to configure the local firewall to
allow all connections from the server. Which kinda defeats the purpose.
If you have control over the NAT why not just assign a dedicated port?
There might still be value in this approach, however. Even though I
have control over the NAT I have multiple clients that might need to
create these connections. I would need to map ports to be able to
handle simultaneous connections.
It's Friday afternoon over here, so I may be wrong...
Janto Dreijer wrote:
Grant Edwards wrote:
>>On 2006-09-15, Janto Dreijer <ja****@gmail.c omwrote:
....
>>>Would it be a reasonable solution to initiate a TCP connection from the client to the server and somehow (?) let the server figure out how the client is connecting? And then send UDP to client over the same (IP, port)?
I doubt that will work unless the firewall has been specificall y designed to recognize that pattern of activity and allow the incoming UDP packets. I don't think most firewall have default rules that allow UDP packets to tunnel back along a TCP connection.
Thanks for the info!
I think you may be right. I had to configure the local firewall to
allow all connections from the server. Which kinda defeats the purpose.
If you have control over the NAT why not just assign a dedicated port?
There might still be value in this approach, however. Even though I
have control over the NAT I have multiple clients that might need to
create these connections. I would need to map ports to be able to
handle simultaneous connections.
It's Friday afternoon over here, so I may be wrong...
Note that TCP and UDP port spaces are disjoint, so there's no way for
TCP and UDP to use "the same port" - they can, however, use the same
port number. Basically the TCP and UDP spaces have nothing to do with
each other.
Most dynamic NAT gateways will respond to an outgoing UDP datagram by
mapping the internal client's UDP port to a UDP port on the NAT
gateway's external interface, and setting a converse mapping that will
allow the server to respond, even though technically there isn't a
"connection ". The NAT table entries will typically be timed out after a
short period of non-use.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Steve Holden wrote:
Note that TCP and UDP port spaces are disjoint, so there's no way for
TCP and UDP to use "the same port" - they can, however, use the same
port number. Basically the TCP and UDP spaces have nothing to do with
each other.
Most dynamic NAT gateways will respond to an outgoing UDP datagram by
mapping the internal client's UDP port to a UDP port on the NAT
gateway's external interface, and setting a converse mapping that will
allow the server to respond, even though technically there isn't a
"connection ". The NAT table entries will typically be timed out after a
short period of non-use.
So are you saying one can't use TCP to punch a hole for UDP? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yawnmoth |
last post by:
so... i'm trying to send some FTP packets, via PHP, and... i'm not
really sure how to construct 'em. HTTP 1.0 packets have the following
structure:
GET http://whatever.com/ HTTP/1.0
Accept: */*
Referer: http://whateveryouwantagain.com/
etc
|
by: KumarForG |
last post by:
hi,
i have a webservice and it's client in dotnet.
the client is coded to assign the proxy property to the service
object, with the proxy url and authentication details.
however, there is a particular configuration with seperate proxy and
firewall where the invocation does not work.
|
by: MikeH |
last post by:
I have the weirdest problem with an Access 97 database...
The application comprises the usual front-back split database. It's
built around Access 97 and had been running without serious problems
for around seven years. The back-ends are replicated across two
servers (althugh I don't think this is a replication problem).
Around two weeks ago users suddenly started to complain about slow
performance. One particular operation that used...
|
by: Sean |
last post by:
Hi, I'm programming an IRC bot. I'm trying to establish a dcc
connection with another IRC client. I give the ipaddress and port
number to the client in the request. I listen to that port with
TcpListener on IPAddress.Any. The listener never receives a
connection.
My situation is the bot computer is behind a router. Is there
something special that must be done to bind to the router's port?
Thanks,
|
by: ygy |
last post by:
When I receive the UDP packets,and then Set the image pixel using
Image::Setpixel(),but When I invalidate the interface to show the image,the
UDP packets missed.How to solve the problem?
thank you in advance!
| |
by: Fraser Dickson |
last post by:
I am building a web based system using ASP.NET and VB.NET
which has to interact with a web service which uses XML
WDDX packets.
I have been given the XML Packet Specification by the Web
Service Provider but can't work out the best way to
interact with the WDDX packets.
Basically the way the Web Service works is that you send
a WDDX formatted Request packet to the given URL, their
|
by: Ryan |
last post by:
Hi,
I am confused with how NetworkStream works.
My application needs to handle heavy requests sent through TCP socket
connection. I use NetworkStream.Read method to get the stream data. The
|
by: jaco.versfeld |
last post by:
Hi There,
I have a basic TCP client and TCP server in C++. The TCP client
connects to the server, and after a setup phase starts to transmit a
file to the TCP server using multiple packets (fixed amount of bytes,
except for the last packet). This is accomplished by using a for loop
and the "int send(socket, buffer, bufferlength, 0)" function.
When I read the packets using "int recv(socket, buffer, 1500, 0)" the
number returned by...
|
by: Naveenv2002 |
last post by:
I am using granados parser for connecting to the telnet and get the data from it. However, every thing appears to be going smooth. But for some reason when I try to write to a string or streamwriter, it looses the final packet. Strangely, If I output the datapackets from the telnet server, it perfectly gets all the packets.
the code snippet is below:
StreamWriter sw = new StreamWriter("c:\\output.txt", true);
public void OnData(byte...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |