Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python tcp

#!/usr/bin/python

import socket
import cPickle
import os
import sys
import signal

PORT = 54321

def handle(cs, addr):
	print "Conn from", addr
	cs.sendall("HAI
")

	try:
		l = cPickle.loads(cs.recv(1024))
		s = sum(l)
		cs.sendall("%d
" % s)
	except:
		cs.sendall("fail :(
")


	cs.sendall("bye
")
	cs.close()

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("0.0.0.0", PORT))
s.listen(100)


while 1:
	(cs, addr) = s.accept()
	pid = os.fork()

	if pid == 0:
		s.close()
		handle(cs, addr)
		sys.exit(0)

	cs.close()
Comment

PREVIOUS NEXT
Code Example
Python :: pandas df where 
Python :: insert in a sorted list python 
Python :: python heroku 
Python :: python numpy 
Python :: yesterday date in python 
Python :: python convert string to raw string 
Python :: launch application from python 
Python :: temp python 
Python :: inverting a dictionary 
Python :: pandas rename column values 
Python :: where are python libraries installed ubuntu 
Python :: print hello world 
Python :: cls in python 
Python :: youtube download in python 
Python :: range parameters python 
Python :: round to 3 significant figures python 
Python :: function in function python 
Python :: divide list into equal parts python 
Python :: py scrapy 
Python :: python loop dictionary 
Python :: how to print multiple strings on one line in python 
Python :: typing racer 
Python :: how to duplicate a row in python 
Python :: rabbitmq python 
Python :: python os.walk 
Python :: what is heapq in python 
Python :: append vector to vector python 
Python :: pandas change column order 
Python :: python string operations 
Python :: calculate sum in 2d list python 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =