diff --git a/Testing/tcpport-client.m b/Testing/tcpport-client.m index 32a4fa637..389244d39 100644 --- a/Testing/tcpport-client.m +++ b/Testing/tcpport-client.m @@ -1,25 +1,45 @@ #include #include -int main () +int main (int argc, char *argv[]) { - id port; + id out_port; + id in_port; id packet; int i; - port = [TcpOutPort newForSendingToRegisteredName: @"tcpport-test" - onHost: @"localhost"]; + if (argc > 1) + out_port = [TcpOutPort newForSendingToRegisteredName: + [NSString stringWithCString: argv[1]] + onHost: @"localhost"]; + else + out_port = [TcpOutPort newForSendingToRegisteredName: @"tcpport-test" + onHost: @"localhost"]; + + in_port = [TcpInPort newForReceiving]; - for (i = 0; i < 5; i++) + for (i = 0; i < 10; i++) { packet = [[TcpPacket alloc] initForSendingWithCapacity: 100 - replyPort: nil]; - [packet writeFormat: @"Here is message number %d\n", i]; - [port sendPacket: packet withTimeout: 20 * 1000]; + replyPort: in_port]; + [packet writeFormat: @"Here is message number %d", i]; + [out_port sendPacket: packet withTimeout: 20 * 1000]; [packet release]; + + packet = [in_port receivePacketWithTimeout: 1000]; + if (packet) + { + fprintf (stdout, "received >"); + fwrite ([packet streamBuffer] + [packet streamBufferPrefix], + [packet streamEofPosition], 1, stdout); + fprintf (stdout, "<\n"); + [packet release]; + } + + sleep (2); } - [port close]; + [out_port close]; exit (0); }