socket applications

lee lee_member at pathlink.com
Wed Feb 22 14:44:19 PST 2006


>>here's a quick client side program:
>>---------------
>>import std.socket;
>>import std.stream;
>>import std.socketstream;
>>import std.stdio;
>>import std.conv;
>>
>>void main()
>>{
>>	char[] Address = GetAddress();
>>	int Port = GetPort();
>>
>>         InternetAddress toAdd =  new InternetAddress(Address, port);
>>
>>         Socket toSoc = new Socket(
>>		AddressFamily.INET,
>>		SocketType.STREAM,
>>		ProtocolType.IP);
>>
>>         toSoc.connect(toAdd);
>>
>>         SocketStream st = new SocketStream(toSoc);
>>
>>		// what to send
>>         char[] req = "Show me the money!!";
>>
>>         st.writeBlock(req.ptr, req.length);
>>
>>		// echo everyting that you can
>>         while(true)
>>                 writef(st.getc);
>>
>>         st.close();
>>}


I've just tested the above code. the functions Getport and GetAddress are not
defined in the included header files. I replaced them with constant values, and
managed to get a succesfull compilation. Unfortunately however, I tried
executing the client program on one of two machines, and it failed to connect
successfully with the second. The second system was running the listener
application that came with the D compiler. The program seems to run fine, and
I'm sure that the correct address and port number was entered into the client
program. If anyone could determine what's wrong with the example given above,
and / or give a reference, I would appreciate it.
Thanks,
lee





More information about the Digitalmars-d mailing list