def client1(): """ <Purpose> Thread for client 1 to connect to server, and send/recv data... """ lind_test_server.connect_syscall(clientsockfd, '127.0.0.1', 50300) lind_test_server.send_syscall(clientsockfd, "test", 0) #Short sleeps are not working, give enough time... emultimer.sleep(1) assert lind_test_server.recv_syscall(clientsockfd, 100, 0) == "test", \ "Write failed in select while processing client 1..." lind_test_server.close_syscall(clientsockfd)
# I'll listen, accept, and connect... serversockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0) clientsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0) # bind to a socket lind_test_server.bind_syscall(serversockfd,'127.0.0.1',50300) lind_test_server.listen_syscall(serversockfd,10) def do_server(): newsocketfd = lind_test_server.accept_syscall(serversockfd) createthread(do_server) # wait for the server to run... sleep(.1) # should be okay... lind_test_server.connect_syscall(clientsockfd,'127.0.0.1',50300) assert(lind_test_server.getpeername_syscall(clientsockfd) == ('127.0.0.1',50300))
import lind_test_server from lind_net_constants import * SyscallError = lind_test_server.SyscallError # let's do a few basic things with connect. This will be UDP only for now... sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0) # should be okay... lind_test_server.connect_syscall(sockfd,'127.0.0.1',50103) # bind will not be interesting... #lind_test_server.bind_syscall(sockfd,'127.0.0.1',50102) # I should be able to retarget it... lind_test_server.connect_syscall(sockfd,'127.0.0.1',50104)
msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK) assert len(msg[2]) == 50, "Length expected 50 bytes to peek, but only" \ + " got " + str(len(msg[2])) + " bytes." except Exception, e: print 'Test:- W:100 P:50 : ', e #Gracefully close the socket lind_test_server.close_syscall(newsockfd) #Run the server in a seperate thread, since client/server should be started #simultaneously. emultimer.createthread(process_request) #connect to server lind_test_server.connect_syscall(clientsockfd, '127.0.0.1', 50300) #send each test with some delay, so that server processes each test cleanly. lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 50, 0) emultimer.sleep(0.1) lind_test_server.close_syscall(clientsockfd) lind_test_server.connect_syscall(clientsockfd2, emulcomm.getmyip(), 50300)
#Both client and server are run from this file, hence opening sockets for both listensockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0) sendsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0) #Bind the socket to an address, this is important in repy, because the recvfrom #_syscall() doesn't work properly without binding the address first. lind_test_server.bind_syscall(listensockfd, '127.0.0.1', 50300) def process_request(): msg = None # Read the data in the socket. try: msg = lind_test_server.recvfrom_syscall(listensockfd, 1024, 0) assert msg != None, "Socket failed to recv message." except Exception, e: print "UDP Connect Test : ", e #Run the listen socket in seperate thread, since send/listen should be started #simultaneously. emultimer.createthread(process_request) emultimer.sleep(0.1) #This is another way to send message in UDP, instead of sendto_syscall(). lind_test_server.connect_syscall(sendsockfd, '127.0.0.1', 50300) lind_test_server.send_syscall(sendsockfd, "UDP Connect Test", 0) #close send & listen sockets... lind_test_server.close_syscall(listensockfd) lind_test_server.close_syscall(sendsockfd)
sendsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0) #Bind the socket to an address, this is important in repy, because the recvfrom #_syscall() doesn't work properly without binding the address first. lind_test_server.bind_syscall(listensockfd, '127.0.0.1', 50300) def process_request(): msg = None # Read the data in the socket. try: msg = lind_test_server.recvfrom_syscall(listensockfd, 1024, 0) assert msg != None, "Socket failed to recv message." except Exception, e: print "UDP Connect Test : ", e #Run the listen socket in seperate thread, since send/listen should be started #simultaneously. emultimer.createthread(process_request) emultimer.sleep(0.1) #This is another way to send message in UDP, instead of sendto_syscall(). lind_test_server.connect_syscall(sendsockfd, '127.0.0.1', 50300) lind_test_server.send_syscall(sendsockfd, "UDP Connect Test", 0) #close send & listen sockets... lind_test_server.close_syscall(listensockfd) lind_test_server.close_syscall(sendsockfd)
import lind_test_server from lind_net_constants import * SyscallError = lind_test_server.SyscallError # let's do a few basic things with connect. This will be UDP only for now... sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0) # should be okay... lind_test_server.connect_syscall(sockfd, '127.0.0.1', 50103) assert (lind_test_server.getpeername_syscall(sockfd) == ('127.0.0.1', 50103)) # I should be able to retarget it... lind_test_server.connect_syscall(sockfd, '127.0.0.1', 50104) # now should change... assert (lind_test_server.getpeername_syscall(sockfd) == ('127.0.0.1', 50104))
assert len(msg[2]) == 50, "Length expected 50 bytes to peek, but only" \ + " got " + str(len(msg[2])) + " bytes." except Exception, e: print 'Test:- W:100 P:50 : ', e #Gracefully close the socket lind_test_server.close_syscall(newsockfd) #Run the server in a seperate thread, since client/server should be started #simultaneously. emultimer.createthread(process_request) #connect to server lind_test_server.connect_syscall(clientsockfd, '127.0.0.1', 50300) #send each test with some delay, so that server processes each test cleanly. lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 100, 0) emultimer.sleep(0.1) lind_test_server.send_syscall(clientsockfd, "A" * 50, 0) emultimer.sleep(0.1) lind_test_server.close_syscall(clientsockfd) lind_test_server.connect_syscall(clientsockfd2, emulcomm.getmyip(), 50300)