Yes it is. In any language. You are probably listening to the same port twice; TCP and UDP endpoints are characterized by IP address and port. "Address already in use" will only be displayed for full compliance, the same address and the same port.
Also make sure the listening port is not yet used with netstat .
UPDATE (thanks to l4mpi): you will get "access denied" if you try to use a port below 1024 without superuser privileges.
UPDATE
I changed your code a bit; one of the problems you encountered was some confusion regarding sending and receiving sockets, which was a “client” function and which was a “server”.
I took the liberty of requesting the body of the message instead of "1", but if necessary it is easy to return things.
from threading import Thread import time import socket CONN = ('localhost', 5455) def fn_client(string, *args): cs = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) while 1: cmd = int( raw_input("command (1 to send): ") ) if (cmd == 1): data = raw_input("message to send: ") cs.sendto(data, CONN) time.sleep(1) def fn_server(string, *args): ss = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) ss.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ss.bind(CONN) while 1: print "Server received '%s'" % (ss.recv(30)) time.sleep(.5) if __name__=='__main__': a = 0 try: Thread(target=fn_client, args=(a, 1)).start() Thread(target=fn_server, args=(a, 1)).start() except Exception, errtxt: print errtxt
source share