示例#1
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."
示例#2
0
import lind_test_server

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

# should work...
lind_test_server.bind_syscall(sockfd, '127.0.0.1', 50102)

# let's set some options!!!    I'll check for function in different tests...
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_LINGER) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_KEEPALIVE) == 0)

# reuseport
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 0)
lind_test_server.setsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT, 1)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_REUSEPORT) == 1)

assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_LINGER) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
                                            SO_KEEPALIVE) == 0)
assert (lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET,
import lind_test_server


from lind_net_constants import *

SyscallError = lind_test_server.SyscallError


sockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

# should work...
lind_test_server.bind_syscall(sockfd,'127.0.0.1',50102)



# let's set some options!!!    I'll check for function in different tests...
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_LINGER)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_KEEPALIVE)==0)


# reuseport
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==0)
lind_test_server.setsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT, 1)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==1)

assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_LINGER)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_KEEPALIVE)==0)
assert(lind_test_server.getsockopt_syscall(sockfd, SOL_SOCKET, SO_REUSEPORT)==1)

示例#4
0
from time import sleep

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

# 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...
import lind_test_server
import emultimer
import emulcomm

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

#Both client and server are run from this file, hence opening sockets for both
serversockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

clientsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)
clientsockfd2 = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

#Bind & listen with backlog of 1, since I am creating only 1 client.
lind_test_server.bind_syscall(serversockfd, '0.0.0.0', 50300)
lind_test_server.listen_syscall(serversockfd, 1)


def process_request():
    """
  <Purpose>
    Process the incoming data using above specifed tests
  """

    rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)

    #Process first test...
    try:
        msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
        assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \
# write should succeed
assert(lind_test_server.write_syscall(myfd, 'hello there!') == 12)

lind_test_server.close_syscall(myfd)

# Now, re open the file

myfd = lind_test_server.open_syscall('/foo', O_RDWR, S_IRWXA)

lind_test_server.close_syscall(myfd)


# 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_STREAM, 0)


# bind will not be interesting...
assert lind_test_server.bind_syscall(sockfd, '10.0.0.1', 50102) == 0
try:
    lind_test_server.setshutdown_syscall(sockfd, SHUT_RD)
except:
    pass

myfd = lind_test_server.open_syscall('/foo', O_RDWR, S_IRWXA)
lind_test_server.close_syscall(myfd)

myfd = lind_test_server.open_syscall('/foo', O_RDWR, S_IRWXA)

lind_test_server.close_syscall(myfd)
示例#7
0
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)
lind_test_server.close_syscall(listensockfd)
import lind_test_server
import emultimer
import emulcomm

from lind_net_constants import *

SyscallError = lind_test_server.SyscallError

#Both client and server are run from this file, hence opening sockets for both
serversockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

clientsockfd = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)
clientsockfd2 = lind_test_server.socket_syscall(AF_INET, SOCK_STREAM, 0)

#Bind & listen with backlog of 1, since I am creating only 1 client. 
lind_test_server.bind_syscall(serversockfd, '0.0.0.0', 50300)
lind_test_server.listen_syscall(serversockfd, 1)


def process_request():
  """
  <Purpose>
    Process the incoming data using above specifed tests
  """

  rip, rport, newsockfd = lind_test_server.accept_syscall(serversockfd)  
  
  #Process first test...
  try:
    msg = lind_test_server.recvfrom_syscall(newsockfd, 100, MSG_PEEK)
    assert len(msg[2]) == 100, "Length expected 100 bytes to peek, but only" \