btiffin
|
Posted: Sat Aug 15, 2009 10:51 pm Post subject: Quick client server with Falcon |
|
|
I'm always a fan of simple interfaces to sockets.
A server side $ facon -i transcipt
code: |
>>> load socket
>>> s = TCPServer()
: TCPServer(){ lastError = Nil}
>>> s.bind("localhost", "12354")
>>> p = s.accept()
: TCPSocket(){ Socket = Class Socket, lastError = Nil, timedOut = Nil, }
|
Client side (different shell) code: |
>>> load socket
>>> t = TCPSocket()
: TCPSocket(){ Socket = Class Socket, lastError = Nil, timedOut = 0, }
>>> t.connect("localhost", "12354")
: false
>>> t.send("12345678")
>>> t.close()
: 8 |
Back to server code: |
>>> p.recv()
ParamError VM0900 at socket:765(PC:ext): Invalid parameters (X, [N])
Traceback:
socket.TCPSocket.recv:765(PC:ext)
falcon.intcomp.__main__:1(PC:12)
>>> ans = p.recv(8)
: "12345678"
>>> p.close()
>>> s.dispose()
>>> inspect(s)
Object of class TCPServer {
accept => Ext. Function TCPServer.accept
bind => Ext. Function TCPServer.bind
dispose => Ext. Function TCPServer.dispose
lastError => Nil
}
>>> inspect(p)
Object of class TCPSocket {
Socket => Class Socket
close => Ext. Function TCPSocket.close
closeRead => Ext. Function TCPSocket.closeRead
closeWrite => Ext. Function TCPSocket.closeWrite
connect => Ext. Function TCPSocket.connect
dispose => Ext. Function Socket.dispose
getHost => Ext. Function Socket.getHost
getPort => Ext. Function Socket.getPort
getService => Ext. Function Socket.getService
getTimeout => Ext. Function Socket.getTimeout
isConnected => Ext. Function TCPSocket.isConnected
lastError => Nil
readAvailable => Ext. Function Socket.readAvailable
recv => Ext. Function TCPSocket.recv
send => Ext. Function TCPSocket.send
setTimeout => Ext. Function Socket.setTimeout
timedOut => int(0)
writeAvailable => Ext. Function Socket.writeAvailable
}
|
Not a bad interface, IMHO.
Cheers, |
|
|