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

Read-line from socket-stream in lisp


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


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)

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))
CL-USER> (echo "hello")
CL-USER> (progn
           (echo "hello")
           (echo "world"))
CL-USER> (progn
           (echo "hello")
           (echo "world")
CL-USER> (progn
           (echo "hello")
           (echo "world")
; No value

Also see:


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

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

ZeroMQ pattern for multiple asynchronous requests to single endpoint

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

websockets - reject a socket connection

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

Sending a Mat object over socket from Java to Java

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

Should I use different WSAOVERLAPPED struct for WSASend and WSARecv?

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

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

I implemented the Last Value Caching (LVC) example of ZMQ (, 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...

Sending files in socket programming 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 =...

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

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 = ""; //---listen at the specified IP and port no.--- IPAddress localAdd = IPAddress.Any; TcpListener listener = new TcpListener(localAdd, PORT_NO); Console.WriteLine("Listening..."); listener.Start();...

TCP Window Update Scenarios

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

Using sockets to build real time chat for iOS?

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?

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

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

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

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

Sending double with tcp from java to C#

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

Socket don't save values in list

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

How to catch socket exceptions on TcpInboundGateway?

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

UDP and TCP always use same IP for one client?

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

parameter error in python script & 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 /Users/myfolder/ japan 1 222299 He configured it on MAC. I am using windows. So my parameter is this way:...

Handling POST request via Socket in Java

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

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

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

How to identify a client connected to AF_UNIX socket?

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

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

I am trying to connect to a sensor using network, the sensor's ip is 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);...

Mixing Java NIO with IO input streams read operation

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)

Python 3.4 listening to selected server and port

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

Chrome UDP sockets not receiving from remote machine

I'm working on a Google Chrome app that contains the following code: var socket = chrome.sockets.udp; var PORT = 5005; var HOST = ''; 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...

Java read bytes from Socket on Linux

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

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

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 : my computer ip: I used a program called hercules as you can see here to connect to the sensor : In...

Continuous data stream from linux command line into python script

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

Use Sockets in multiple *.cpp files

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

Merging socket request/response in a function

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

Sockets make no sense?

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

Coverity - overrun of struct type

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

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

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 and the sails sockets. I mean good...

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

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

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

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

Socket.IO message doesn't update Angular variable

I have a client-server setup with AngularJS running on the client. // Server.js var io = require('')(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...

how should a message look like to be a response

I have read and followed the example in 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...

Are the C functions recvfrom and sendto mutually exclusive?

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

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

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

Popen.subprocess in threads

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

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

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

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

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

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

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/",...

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

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

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

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

Making socket communication using bin_prot

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