sockets,tcp,lisp,common-lisp,usocket , Read-line from socket-stream in lisp


Read-line from socket-stream in lisp

Question:

Tag: sockets,tcp,lisp,common-lisp,usocket

I am working on a TCP client in lisp, and am having difficulties reading/printing the socket-stream correctly. When the client sends data to the server it should receive a response, and I need to write this to stdout. This works correctly, except I am having an issue where the response is printing twice. If I have multiple commands being sent, only the last one will be printed twice. Here is my code:

(defun socket-print (string socket)
    (write-line string (usocket:socket-stream socket))
    (force-output (usocket:socket-stream socket)))


(defun socket-read (socket)
    (write-line (read-line (usocket:socket-stream socket) nil)))


(defun mytest (command)
    (let ((socket (usocket:socket-connect _IP_ _PORT_)))
        (socket-print command socket)
        (socket-read socket)))

Answer:

I don't think it's printing twice. I think it's printing (via write-line) once, and then write-line is returning the line, and the REPL is printing the return value. E.g., if you modify your mytest to return nil, I think you'll see the output that you're expecting:

(defun mytest (command)
    (let ((socket (usocket:socket-connect _IP_ _PORT_)))
        (socket-print command socket)
        (socket-read socket)
        nil))

This should print the line with write-line, and then return nil, and the REPL will print nil. Compare this with:

CL-USER> (defun echo (line)
           (write-line line))
ECHO
CL-USER> (echo "hello")
hello
"hello"
CL-USER> (progn
           (echo "hello")
           (echo "world"))
hello
world
"world"
CL-USER> (progn
           (echo "hello")
           (echo "world")
           nil)
hello
world
NIL
CL-USER> (progn
           (echo "hello")
           (echo "world")
           (values))
hello
world
; No value

Also see:


Related:


Popen.subprocess in threads


python,multithreading,sockets,popen
I have a client server code in python, wherein the client queries the server about a process running on the server and provides the memory threshold. If the process consumes more memory than the threshold,the server kills the process and restarts it. The problem is since I am creating a...

Use Sockets in multiple *.cpp files


c++,sockets,server
As you can see in the Title box, I´d like to find a way how to use my sockets in multiple cpp files. #pragma comment(lib,"ws2_32.lib") void main() { WSADATA wsaData; WSAStartup(MAKEWORD(2,0), &wsaData); SOCKET slisten,client; slisten = socket(AF_INET,SOCK_STREAM, 0); //and so on... } This is the way I use the ws2_32.lib...

Continuous data stream from linux command line into python script


python,linux,command-line,tcp,pipe
I need to get a continuous stream of data flowing from a peripheral device, to a raspberry pi, and lastly to my computer (mac). So far, the data is can make its way continuously (in real time) from the peripheral, to the command line of my raspberry pi. Note that...

UDP and TCP always use same IP for one client?


python,sockets,networking,tcp,udp
I've made a server (python, twisted) for my online game. Started with TCP, then later added constant updates with UDP (saw a big speed improvement). But now, I need to connect each UDP socket client with each TCP client. I'm doing this by having each client first connect to the...

Python 3.4 listening to selected server and port


python,sockets
This code can create socket, connect to selected server and port, and print reply. I have a question, how can I listening to the port longer than one moment? E.g. I want listen to selected port for 20 seconds and print all packets which will come at this time. Is...

Handling POST request via Socket in Java


java,sockets,http,post,request
I'm trying to handle a simple POST Request in Java using a Socket. I can receive the request header and answer the request without any problem, but I certainly can not get the body of the request. I read somewhere that I'd need to open a second InputStream to achive...

What type of database is the best for storing array or object like data [on hold]


database,node.js,sockets
I'm just curious what the best method would be if I'm trying to have a bot running on my Node server that I could play Blackjack against. But for multiple connected clients via sockets, each connected socket will have their own bot to play against but I need some way...

Moving a SIte from Drupal to Raw PHP … Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)


php,mysql,sockets,drupal,drupal-7
I don't understand this the error, Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) I am not familiar with drupal or any frameworks. Please advice me about this error and if I want to host my raw php site which I created in local WAMP server and...

When BSD socket reports that RST was received, if not everything was read yet


c,sockets,tcp
Lets imagine the following data sequence that was sent from the server to the client: [data] [data] [data] [FIN] [RST] And lets imagine that I'm doing the following on the client side (sockets are non-blocking): char buf[sizeof(data)]; for (;;) { rlen = recv(..., buf, sizeof(buf), ...); rerr = errno; slen...

How to get the socket's specific error reason when POLLERR happens?


sockets,epoll
When POLLERR comes up after polling, how can I determine the specific error reason?

Set a timeout for an UDP socket with Twisted (python)


python,sockets,twisted
I'm using Twisted in a python program. I send data every minute and receive data on a UDP socket and I need to set a timeout. I found a way to do this, but I would like to know if it's a good way to do that. This is the...

Should I use different WSAOVERLAPPED struct for WSASend and WSARecv?


windows,sockets,winsock,winsock2
I'm developing a server-client application using WinSock. Does using the same WSAOVERLAPPED with both WSASend and WSARecv works well? Should I use different WSAOVERLAPPED struct for WSASend and WSARecv?...

Sockets make no sense?


javascript,node.js,sockets
I'm using the 'ws' library for Node.js. I can write code that sends data from my server to my client, posting a date and time update, and closes the socket when I click a button; var wss = new WebSocketServer({server: server}); console.log("WebSocket server created"); wss.on('connection', function(socket) { // SEND DATE...

ZeroMQ pattern for multiple asynchronous requests to single endpoint


sockets,asynchronous,zeromq
I'm using zmq to develop a distributed application having the following network topology: a client node that initiates a request and a server node that replies to requests. Since the client is a node.js application I can't block after a send call to wait the response, so the scenario is...

Mixing Java NIO with IO input streams read operation


java,sockets,io,nio
I need to use NIO to allow the server side to support timeout on write operations, but handling reading operations on the socket channels complicates my program. I was wondering if it's possible to write to the sockets using NIO but to read using regular IO, something like ((SocketChannel) selectedKey.channel()).socket().getInputStream().read(buffer)...

The requested address is not valid in its context when i try to listen a port


c#,sockets,listener,port
I am trying to connect to a sensor using network, the sensor's ip is 192.168.2.44 on port 3000; My Code: byte[] byteReadStream = null; // holds the data in byte buffer IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("192.168.2.44"), 3000);//listen on all local addresses and 8888 port TcpListener tcpl = new TcpListener(ipe); while...

Java read bytes from Socket on Linux


linux,windows,sockets,network-programming,raspberry-pi
I'm trying to send a file from my Windows machine to my Raspberry-Pi 2, and I have a client and a server. The client should be able to send a zip file over the network to my server on my linux machine. I know my client and server work on...

C: Linux to Windows: Sending text file over TCP produces not exact copy on the Windows side


c,linux,windows,sockets,tcp
I'm writing a system to gather software/hardware info on Macs to put it into a Windows-based SQLite3 database. Schema is as following: agent on Mac - gather data, then sends it over Internet, using SSL, to small Linux server in DMZ (this part works as intended so far) Linux server...

Specified argument was out of the range of valid value to get data from network in c#


c#,sockets,buffer,streamwriter
I am trying to send a command to a sensor and get the data from it using this code : const int PORT_NO = 3000; const string SERVER_IP = "192.168.2.44"; //---listen at the specified IP and port no.--- IPAddress localAdd = IPAddress.Any; TcpListener listener = new TcpListener(localAdd, PORT_NO); Console.WriteLine("Listening..."); listener.Start();...

ZMQ: No subscription message on XPUB socket for multiple subscribers (Last Value Caching pattern)


python,sockets,proxy,zeromq,publish-subscribe
I implemented the Last Value Caching (LVC) example of ZMQ (http://zguide.zeromq.org/php:chapter5#Last-Value-Caching), but can't get a 2nd subscriber to register at the backend. The first time a subscriber comes on board, the event[0] == b'\x01' condition is met and the cached value is sent, but the second subscriber (same topic) doesn't...

Communicating between a PC and UR5 Universal Robotics Robot Arm using TCP/IP LabVIEW


sockets,networking,tcp,labview,robotics
I have a UR5 Universal Robotics Robot Arm and PC connected via ethernet that I am attempting to have talk to each other via LabVIEW (just send strings back and forth). I have already managed to read communication from the robot to the PC using the TCP Listen VI and...

Running a python script online for free (and accessing using ip and port) [closed]


python,sockets,web-hosting,host
I coded a python script to run a server for my iPhone messaging app. This app/server uses (currently) port 80 and ip localhost to run the server as I am running it on my computer so far. Now I need a host to run the script and allow me to...

Chrome UDP sockets not receiving from remote machine


javascript,sockets,google-chrome,udp,google-chrome-app
I'm working on a Google Chrome app that contains the following code: var socket = chrome.sockets.udp; var PORT = 5005; var HOST = '127.0.0.1'; socket.create({}, function(sockInfo){ socket.bind(sockInfo.socketId, HOST, PORT, function(result){ socket.onReceive.addListener(function(info){ // do stuff with the packet data }); }); }); This mechanism worked perfectly when I was sending data...

Creating Multi-user chat with sockets on python, how to handle the departure of the server?


python,sockets
I was trying to implement a multiuser chat (group chat) with socket on python. It basically works like this: Each messages that a user send is received by the server and the server sends it back to the rest of the users. The problem is that if the server close...

Socket.IO message doesn't update Angular variable


javascript,angularjs,node.js,sockets
I have a socket.io client-server setup with AngularJS running on the client. // Server.js var io = require('socket.io')(server); io.on('connection', function (socket) { socket.on('message', function (msg) { //console.log(msg); console.log(msg); io.emit('message', msg); }); }); As observed, it essentially emits a message events with the data stored in the variable msg. And then...

Sending double with tcp from java to C#


java,c#,.net,sockets,tcp
I have a Java SocketServer that sends doubles to a C# client. The sever sends the doubles with DataOutputStream.writeDouble() and the client reads the double with BinaryReader.ReadDouble(). When I send dos.writeDouble(0.123456789); and flush it from the server the client reads and outputs 3.1463026401691E+151 which is different from what I sent....

Connect to pressure sensor using c# to get the value ,doesn't work in c#


c#,sockets,listener,tcpclient,tcpserver
I have a sensor ,i connect to this sensor using network cable.I should send a command to this sensor to get the value . The sensor ip is :192.168.2.44 my computer ip:192.168.2.111 I used a program called hercules as you can see here to connect to the sensor : In...

how should a message look like to be a response


java,tcp,spring-integration
I have read and followed the example in http://docs.spring.io/spring-integration/reference/html/ip.html#ip-correlation I have a spring-integration server <int-ip:tcp-connection-factory id="socketserver" type="server" port="30124" using-nio="true" mapper="mapper" deserializer="jsonSerializer" serializer="jsonSerializer" single-use="false"/> with this mapper from above link: <bean id="mapper" class="org.springframework.integration.ip.tcp.connection.MessageConvertingTcpMessageMapper"> <constructor-arg...

Coverity - overrun of struct type


c,sockets
I am getting the following error through the coverity tool - overrun-buffer-arg: Overrunning struct type in_addr of 4 bytes by passing it to a function which accesses it at byte offset 7 using argument "8UL". sample code: static u_long addr; static struct sockaddr_in remote_server; addr = inet_addr(remote_servername); memcpy((char *) &remote_server.sin_addr,...

parameter error in python script & TOR proxy server


python,sockets,subprocess,tor,proxy-server
I am Noob in Python. My Boss instructed me to run this python script with TOR proxy server running. He told me to pass this parameter this way: python DownloadYP.py /Users/myfolder/ japan http://www.jpyellow.com/company 1 222299 He configured it on MAC. I am using windows. So my parameter is this way:...

Tornado behind Nginx, should I use TCP nodelay config in python or nginx.conf?


nginx,tcp,websocket,tornado
I have a Tornado server running behind Nginx reverse proxy. The proxy is configured with tcp_nodelay: on. I see there's also an option to call WebSocketHandler.set_nodelay(True) on a WebSocket instance once it's connected. Do these two create the same effect? Are there pro's con's for using one over the other?...

Python3:socket:TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes'


sockets,python-3.x
I am try to use python socket package to implement an echo server. But it continuously occurs the error: TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes', is there any errors in my code? here is the error: Exception in thread Thread-1: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py",...

Are the C functions recvfrom and sendto mutually exclusive?


c,linux,sockets,udp,thread-safety
I have one thread calling recvfrom with a timeout of 100 ms in a loop. Another thread calls sendto periodically. Does the sendto function wait until the recvfrom is released by the timeout (or a successful read) or does it send the data during that period of time....

Merging socket request/response in a function


c#,sockets,mono
I'm trying to implement a client/server application communicating through sockets. The communication works fine and I can match and execute different functions. Most of the packets are from request / response type and are matched with a persistent sequence number. The problem I'm now stating is that I can't lead...

Socket don't save values in list


java,multithreading,sockets,arraylist
I'm new in network developing in Java and I want to create a simple Socket server, that get values from client and collects all of them in ArrayList. I wrote an example code, but in server side it not collecting the strings. This is my server side: Server public class...

Making socket communication using bin_prot


sockets,ocaml,communication
I want to make Socket communication using bin_prot in OCaml. However, I can't find any detailed explanation or example to do that. I made Socket communication in the other way before, so I know the flow of it. Do you have good explanations or examples to make Socket communication using...

Sending files in socket programming tcp


c++,sockets,tcp
I am trying to implement a simple file transfer. Below here is two methods that i have been testing: Method one: sending and receiving without splitting the file. I hard coded the file size for easier testing. sender: send(sock,buffer,107,NULL); //sends a file with 107 size receiver: char * buffer =...

How to catch socket exceptions on TcpInboundGateway?


java,spring,sockets,spring-integration
I'm using TcpInboundGateway from spring-integration for a socket client. In TcpInboundGateway.doOnMessage() the stream is send via the socket connection. If an exception occurs eg because the socket is closed, there is just a spring error log "Failed to send reply". BUT I'd like to handle those socket errors explicit. How...

Only one usage of each socket address (protocol/network address/port) is normally permitted in c#


c#,sockets,listener,tcpclient
I am trying to connect to a sensor using network, the sensor's ip is 192.168.2.44 on port 3000; try { byte[] byteReadStream = null; // holds the data in byte buffer IPEndPoint ipe = new IPEndPoint(IPAddress.Any, 3000); //listen on all local addresses and 8888 port TcpListener tcpl = new TcpListener(ipe);...

Using sockets to build real time chat for iOS?


ios,objective-c,sockets,chat,real-time
If I wanted to build a real time chat app for iOS using Objective-C, what would be the best way of going about it?

Sending a Mat object over socket from Java to Java


java,sockets,opencv,mat
I understand Sockets over Java and sending Int,String,bytes etc over it. What i just want to know is that is there a way to decode a Mat object to byte array and then send it over java socket and then retrieve back the Mat object from the byte received? Till...

Sails.js sockets. Good and bad sides. Difference with socket.io


javascript,node.js,sockets,socket.io,sails.js
So I am learning Sails.js at the moment and more specifically the integrated socket functionality of the framework. I do like the framework because it is very good for building APIs. My question is can you guys give me some comparison between socket.io and the sails sockets. I mean good...

How to identify a client connected to AF_UNIX socket?


python,sockets
What is the meaning of the "client address" in case of AF_UNIX sockets in Python? sock = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) sock.bind( "/tmp/sock" ) sock.listen( 1 ) while True: connection, client_address = sock.accept() print( client_address ) # prints : b'' Is there a way to obtain on the server side...

websockets - reject a socket connection


node.js,sockets,websocket
I'm using ws as the socket library for my node.js library. so my question is, how can I reject a connection if the user doesn't pass the authorization process. var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({port: 6969}); wss.on('connection', function(socket){ // if the socket.upgradeReq.headers.cookie doesn't exists, reject the client...

TCP Window Update Scenarios


networking,tcp,webserver
In our application, we are using apache tomcat webserver running in 8081. It receives POST message from Client at 16:42:06.87 IST timeframe. It acknowledges by ACK packet with window size of 62356 bytes after 200ms. After some seconds (3-5 seconds), it also sends similar ACK packet but as a "TCP...