1996-03-01 16:26:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <objects/TcpPort.h>
|
|
|
|
|
1996-03-06 14:44:21 +00:00
|
|
|
int main (int argc, char *argv[])
|
1996-03-01 16:26:49 +00:00
|
|
|
{
|
1996-03-06 14:44:21 +00:00
|
|
|
id out_port;
|
|
|
|
id in_port;
|
1996-03-01 16:26:49 +00:00
|
|
|
id packet;
|
|
|
|
int i;
|
|
|
|
|
1996-03-06 14:44:21 +00:00
|
|
|
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];
|
1996-03-01 16:26:49 +00:00
|
|
|
|
1996-03-06 14:44:21 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
1996-03-01 16:26:49 +00:00
|
|
|
{
|
|
|
|
packet = [[TcpPacket alloc] initForSendingWithCapacity: 100
|
1996-03-06 14:44:21 +00:00
|
|
|
replyPort: in_port];
|
|
|
|
[packet writeFormat: @"Here is message number %d", i];
|
|
|
|
[out_port sendPacket: packet withTimeout: 20 * 1000];
|
1996-03-01 16:26:49 +00:00
|
|
|
[packet release];
|
1996-03-06 14:44:21 +00:00
|
|
|
|
|
|
|
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);
|
1996-03-01 16:26:49 +00:00
|
|
|
}
|
|
|
|
|
1996-03-06 14:44:21 +00:00
|
|
|
[out_port close];
|
1996-03-01 16:26:49 +00:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|