I'm getting closer. I think that I'm correctly hiding most of the network code into a networkManager function, so that I can now have a top-level that looks something like this:
Code: Select all
int main(void) {
chan xtcp[1];
par {
on stdcore[1]: testTcp(xtcp[0]);
on stdcore[2]: networkManager(xtcp, 1);
}
return 0;
}
So, now I'm having trouble using the xtcp code (an xtcp client demo would be great). I seem to be able to almost complete a connection to a simple Python server with the following code:
Code: Select all
void testTcp(chanend xtcp) {
xtcp_ipaddr_t host = {192,168,1,100};
xtcp_connect(xtcp, 8000, host, XTCP_PROTOCOL_TCP);
When I run this, interestingly enough, my server won't show that the connection has been made until the XC-2 times out (apparently). Then, I get this from my Python server:
Code: Select all
waiting for connection
connected to ('192.168.1.149', 1026)
waiting for data
Traceback (most recent call last):
File "tcptest.py", line 11, in <module>
data = conn.recv(1024)
socket.error: (10054, 'Connection reset by peer')
So, I imagine that I need to do something to complete the connection initiation, which I'm now completely guessing, has to do with waiting for the connection event. I tried recoding my example as:
Code: Select all
void testTcp(chanend xtcp) {
xtcp_conn_or_config_t event_type;
xtcp_config_event_t event;
xtcp_ipconfig_t ipconfig;
xtcp_connection_t conn;
xtcp_ipaddr_t host = {192,168,1,100};
xtcp_connect(xtcp, 8000, host, XTCP_PROTOCOL_TCP);
//xtcp_ask_for_conn_or_config_event(xtcp); // is this needed?
printstrln("connection attempted");
slave {
xtcp_conn_or_config_event(xtcp, event_type, event, ipconfig, conn);
}
But no luck. Is there anybody that can supply a simple tcp client demo using the xtcp lib?
For completeness, here's my test Python code:
Code: Select all
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 8000))
s.listen(1)
print 'waiting for connection'
conn, addr = s.accept()
print 'connected to', addr
print 'waiting for data'
while True:
data = conn.recv(1024)
if not data:
break
else:
print data
conn.close()