-
Notifications
You must be signed in to change notification settings - Fork 4
/
client1.py
executable file
·44 lines (35 loc) · 1.04 KB
/
client1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
import socket
import os
import sys
import signal
client1 = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client1.connect(('192.168.1.6',8081)) #ip address of machine where server is running
def inp():
while True:
try:
message = raw_input('Me: ')
if message:
client1.send(message)
if message == '\q':
print "<--Exiting... Goodbye! -->"
break
except:
break
def outp():
while True:
data = client1.recv(180)
if data:
if data == '\q':
print "<--Exiting... Goodbye! -->"
break
print '\nReceived: ',data
newpid = os.fork()
if newpid == 0: #child process
outp()
parentId = os.getppid()
os.kill(parentId,signal.SIGKILL) #kill parent, then exit
else:
inp()
parentId = os.getpid() #pid returns own, ppid returns parent's process id
os.kill(parentId,signal.SIGKILL)