Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Creates a random UDP socket (for media) and returns the socket,
the IP and the port of this socket.

        def createMediaSockets(ip=None, port=None):
	"""Creates a random UDP socket (for media) and returns the socket,
	the IP and the port of this socket.
	"""
	if ip is None:
		ip = Config.LOCAL_IP
	if port is None:
		port = 0
		port2 = 0
	else:
		port2 = port + 1
	success = False
	while not success:
		sock = socket.socket(Config.socket_type, socket.SOCK_DGRAM)
		sock2 = socket.socket(Config.socket_type, socket.SOCK_DGRAM)
		try:
			sock.bind((ip, port))
			if port2 == 0:
				ret_ip, port = sock.getsockname()
				port2 = port + 1
			try:
				sock2.bind((ip, port2))
				if (port % 2 == 0):
					Log.logDebug("Media sockets bound, RTP: " + str(ip) + ":" + str(port) + ", RTCP: " + str(ip) + ":" + str(port2), 1)
					ret_pair = (sock, sock2)
					success = True
				else:
					sock = socket.socket(Config.socket_type, socket.SOCK_DGRAM)
					port = port + 2
					try:
						sock.bind((ip, port))
						port, port2 = port2, port
						Log.logDebug("Media sockets bound, RTP: " + str(ip) + ":" + str(port) + ", RTCP: " + str(ip) + ":" + str(port2), 1)
						ret_pair = (sock2, sock)
						success = True
					except socket.error:
						sock2.close()
						port = port2 + 3
						port2 = port + 1
			except socket.error:
				sock.close()
				port = port + 2
				port2 = port + 1
		except socket.error:
			port = port + 1
	return ret_pair, ret_ip, port
        


src/s/f/sftf-HEAD/TestCase.py   sftf(Download)
from SipReply import SipReply
from SipMessage import SipMessage
from NetworkEventHandler import createMediaSockets, compareHostNames, NetworkEventHandler, getTransportNumber
from FileEventHandler import FileEventHandler
import time, socket
		"""
		if sock is None:
			sockpair, ip, port = createMediaSockets()
		else:
			ip, port = sock.getsockname()