Thursday 15 May 2014

sockets - Receiving data through LISP USOCKET -


I am trying to send the data when the data reaches the server, the server should respond. However, stream-read (as defined below) returns only the data, when it resonates with the original data sent back, for example, if I type Hello And the server responds with the same data, then Hello , then returns stream read , but if the server responds Hello , With the stream read until the server returns the exact buffer it receives .

Here's the code: (I've found most of them online.)

  ;; Load UScat (Load # P "/usr/share/common-lisp/source/cl-asdf/asdf.lisp") (asdf: operating 'asdf: load-op: usocket) (defunct stream-read (stream) (socket ) -Litan (Socket Stream Stream)) (): (String Stream) (List-Line String (Make: Socket-Stream Stream)) (Force-Output (Socket Stream Stream))); ; Define a stream (defparameter my-stream (memory: socket-connect "127.0.0.1" 6003)) ;; Use the stream (stream print "random" my-stream) (print (stream-read-meri-stream))   

For the server, I'm using a slightly modified version Boost server example blocking (C ++) Full code can be found here:

  ... zero session (socket_ptr sock) {try {for (;;) {char data [max_length]; Boost :: system :: error_code error; Size_t length = sock-> Read_some (boost :: asio :: buffer (data), error); If (error == boost :: asio :: error :: eof) break; The colleague closed the connection. Else if (error) boost: system :: system_error (error); // some other error std :: vector & lt; Four & gt; V (data, data + length); Std :: string thetrtr; For (unsigned int i = 0; i  = 0x7f); // Insert non-ASIAN four and thetrtr (theStr.end (), V [i]); } Std :: cout & lt; & Lt; "|" & Lt; & Lt; TheStr & lt; & Lt; "|" & Lt; & Lt; Std :: endl; Boost :: asio :: write (* sock, boost :: asio :: buffer (data, length)); // Work Boost: ASIO :: Write (* Sock, Promotion :: ASO :: Buffer ("Something", 4)); // does not work}} hold (std :: exception & e) {std :: cerr & lt; & Lt; "Exception in thread:" & lt; & Lt; E.what () & lt; & Lt; "\ N"; }} ...   

Without seeing the code for your server it is difficult to answer without speculation But a bit of:

  1. If you use the same socket for each call from the client to the server, if the server is not expecting it, it will not behave as if You wish.

  2. Stream-read call socket-listen . Did you mean the utility: socket-listen ? This is a server-side function (and takes different arguments). I'm probably not seeing the exact code that you were running.

  3. Consultant Note: (A) My stream is actually a socket, not a stream; (B) I encourage you to manage external libraries.

    Here is a complete work example. It is on Lispowersx; I have used LW internals for the server which makes it completely clear which is the server and which is the client.

      CL-USER 1> (Ql: quickload: usocket) To load "usocket": Load 1 ASDF system: USB; Loading "USB" (: USOKette) CL-User2 & gt; (Com: Start-up-Server: Service 6003: Function (Lambda (Handle) (Walk * ((stream (make-instance 'com: socket-stream: socket handle: direction: Io: element-type' base-four)) (Line stream ("Streamline")) (format stream "Hello: ~ A ~%" line) (Force-Output stream)) # & lt; mp3 process name "6003 server" priority 85000000 state "Running" Gt; CL-User 3> (Defun socket-read (socket) (read-line (maker: socket-stream socket)) Socket-read CL-User 4 & gt; (ST Ring socket) (empty socket-print (string socket) (list-line string (socket-stream socket)) (force-output socket) socket-print CL-user 5> (socket-print socket) ) (Socket-reading socket)) Test CL-User 6 & gt; (Socket-Connect "127.0.0.1" 6003)) (Test "Mast Toast") "Hello: Butterd Toast" Zero CL-User 7 & gt; ("A good cup of tea") "Hello: a good cup of tea" NIL   

    If you are still having problems, then post again with the source of your server and your Read the actual stream .

No comments:

Post a Comment