Socket struggles...
Torbjörn Lager
lager at ling.gu.se
Wed Aug 7 22:03:25 CEST 2002
Hi Valentin,
Thanks for your advice. It now works the way it should...
Cheers,
Torbjorn
Valentin Mesaros wrote:
> Torbjörn,
>
> Your client is ok.
> Your server, instead, has a small problem: you should use the new
> created socket to write to (i.e., A instead of Server).
> So, replace this line:
> {Server write(vs:"Hello client!\n")}
>
> with this one:
> {A write(vs:"Hello client!\n")}
>
> I believe you make the same error with your server in Java.
>
> By the way, I saw you use 'all' when reading from the socket. Pay
> attention; this will block the current thread until all the socket is
> read (i.e., the socket is closed).
>
> Valentin
>
>
> Torbjörn Lager wrote:
>
>>Hi All,
>>
>>I want to set up a socket connection between an existing Java program
>>(client) and an Oz program (server). The client sends one (sometimes
>>fairly large) text string to the server. The server does some processing
>>on it and sends back the result (also a string, fairly large). The
>>client may send new string before the server has finished processing the
>>old one. I have read the documentation for sockets (in the Open
>>Programming doc), read some relevant stuff in the mailing list
>>archives, and experimented a bit, but I'm still not sure how to this in
>>the best possible way. In fact, I can't get bidirectional communication
>>to work at all :-(
>>
>>In the following programs I simulate the Java client by an Oz program:
>>
>>The server (in one OPI window):
>>
>>declare
>>
>>class Accepted from Open.socket
>> meth getInfo($)
>> {self read(list:$ size:all)}
>> end
>>end
>>
>>proc {Accept}
>> A
>>in
>> {Server accept(acceptClass:Accepted
>> accepted:?A)}
>> {Browse thread {A getInfo($)} end}
>> {Browse 'reached this point'}
>> {Server flush}
>> {Server write(vs:"Hello client!\n")}
>> {Server flush}
>> {Accept}
>>end
>>
>>Server = {New Open.socket init}
>>{Server bind(host:localhost takePort:4096)}
>>{Server listen}
>>{Accept}
>>
>>The client (in another OPI window):
>>
>>declare
>>
>>C1={New Open.socket client(host:localhost port:4096)}
>>{C1 write(vs:"Hello server!\n")}
>>{C1 flush}
>>{Browse thread {C1 read(list:$ size:all) } end }
>>
>>The server receives the message from the client, but the server's
>>response isn't received by the client. I'm sure there are things I don't
>>understand here... Please help!
>>
>>Cheers,
>>Torbjorn
>>
>>-
>>Please send submissions to users at mozart-oz.org
>>and administriva mail to users-request at mozart-oz.org.
>>The Mozart Oz web site is at http://www.mozart-oz.org/.
>
> -
> Please send submissions to users at mozart-oz.org
> and administriva mail to users-request at mozart-oz.org.
> The Mozart Oz web site is at http://www.mozart-oz.org/.
>
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
More information about the mozart-users
mailing list