socket applications

BCS BCS_member at pathlink.com
Wed Feb 22 15:05:31 PST 2006


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...



More information about the Digitalmars-d mailing list