コード例 #1
0
def tester():
  # need simultaneous communication...
  emultimer.createthread(helper)
  emultimer.sleep(0.1)

  lind_test_server.send_syscall(sockets[1], "SocketPair test.", 0)

  msg = None
  msg = lind_test_server.recv_syscall(sockets[1], 1024, 0)
  assert msg != None, "Sockpair recv failed in tester..."

  emultimer.sleep(0.1)

  lind_test_server.close_syscall(sockets[1])
  lind_test_server.close_syscall(sockets[0])

  return
コード例 #2
0
def tester():
    # need simultaneous communication...
    emultimer.createthread(helper)
    emultimer.sleep(0.1)

    lind_test_server.send_syscall(sockets[1], "SocketPair test.", 0)

    msg = None
    msg = lind_test_server.recv_syscall(sockets[1], 1024, 0)
    assert msg != None, "Sockpair recv failed in tester..."

    emultimer.sleep(0.1)

    lind_test_server.close_syscall(sockets[1])
    lind_test_server.close_syscall(sockets[0])

    return
コード例 #3
0
# 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))



コード例 #4
0
    #Process fourth test...
    try:
        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)
コード例 #5
0
        assert lind_test_server.read_syscall(sock, 4) == "test", \
          "Failed to read from a file..."
        #test for file finished, remove from polling.
        to_go = [x for x in polled if x['fd'] == sock]
        map(polled.remove, to_go)
      else:
        lind_test_server.send_syscall(sock, data, 0)
        #Data is sent out of this socket, it's no longer ready for writing,
        #modify it only read mode.
        [x for x in polled if x['fd'] == sock][0]['events'] = \
          lind_test_server.POLLIN

  lind_test_server.close_syscall(serversockfd)

#Thread for running server ...
emultimer.createthread(process_request)
emultimer.sleep(1)

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..."
コード例 #6
0
# let's do a few basic things with connect.   This will be UDP only for now...

listensockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)
sendsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)

def recvmessages():
  # let's wait for packets here...
  lind_test_server.bind_syscall(listensockfd,'127.0.0.1',50102)
  assert lind_test_server.recv_syscall(listensockfd,10000,0) == 'test',\
    "UDP recv test 1 failed."
  lind_test_server.recv_syscall(listensockfd,10000,0) == 'test2',\
    "UDP recv test 2 failed."

# I need a thread...
createthread(recvmessages)

# let's wait for it to start...
sleep(.1)

# send a message
lind_test_server.sendto_syscall(sendsockfd,'test','127.0.0.1',50102,0)

# get another socket, bind and then send
sendsockfd2 = lind_test_server.socket_syscall(AF_INET, SOCK_DGRAM, 0)
lind_test_server.bind_syscall(sendsockfd2,'127.0.0.1',50992)
lind_test_server.sendto_syscall(sendsockfd2,'test2','127.0.0.1',50102,0)

sleep(0.1)
lind_test_server.close_syscall(sendsockfd2)
lind_test_server.close_syscall(sendsockfd)