socket applications
Alex Kravetz
Alex_member at pathlink.com
Wed Feb 22 18:14:29 PST 2006
In article <dtiqnr$8e0$2 at digitaldaemon.com>, BCS says...
>
>lee wrote:
>>>>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
>>
>>
>Oops x-P !! I intended to say that Getport and GetAddress were stand ins for
>whatever.
>
>I known they worked a while ago... Hmm...
change ProtocolType.IP to ProtocolType.TCP
More information about the Digitalmars-d
mailing list