sockets , Python sockets will not connect

Python sockets will not connect


Tag: sockets

I'm trying to run a server and a client on two separate Windows 7 machines on the same network using sockets in Python 2.7. First I'm just trying to get them to connect before trying to do anything.

Currently my server is:

import socket    

host = '' #Also tried '', 'localhost', gethostname()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, 12345))
cs, addr = s.accept()

print "Connected."

My client is:

import socket

host =  '' #Also tried 'localhost', gethostname()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(host, 12345)

print "Connected."

The error I get is:

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it. 

I've looked through lots of other questions but none of the answers solved my problem. Any help is appreciated.

When I use the IP address of the server ( as the host for the client, I get

[Errno 10060] A connection attempt failed because the connected party did not properly 
respond after a period of time, or established connection failed because connected host has 
failed to respond


You are saying these are two separate machines. You cannot reach the one machine from the other by connecting to or localhost.

Listening on is fine, this means that the listening socket is reachable from all interfaces, including the local network.

However, for connecting to your server, you obviously need to use the IP address (or hostname, if you have properly set up a local name server) of your server machine in the local network.

Per your comment, the local IP address of your server machine is That means you should end up calling s.connect("", 12345).


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

Jetty Web Socket Timeout

I am trying to establish a Web Socket Connection using Jetty 9.3.0 RC. function checkDetails(port) { var ws = new WebSocket("ws://localhost:9995/application"); ws.onopen = function(event) { console.log("onopen called..."); } ws.onerror = function(event){ console.log('onerror called...'); } ws.onmessage = function(event) { console.log("onmessage called..." +; } ws.onclose = function(event) { console.log("onclose called..." +...

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

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

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

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

Updating a two-way java messenger chat to allow multiplie users

I just finished an youtube series about creating an instant messenger chat, which works between the server and one client through sockets. However, I'd like to improve this chat so multiple clients can connect at the same time. The server works fine, and so does the first client. On the...

Reading packets from a client stops after 1 or 2 received

I'm writing a server program in C that will read commands from the client. Commands are in the form of 5 byte packets, and the client will be sending a bunch of them in succession. The code I have to read each command is: while(1) { char buffer[1024]; int alreadyread...

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

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

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

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

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

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

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

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

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 choose zmq maximum buffer size properly?

According to ZMQ-manual The ZMQ_SNDBUF option shall retrieve the underlying kernel transmit buffer size for the specified socket. A value of zero means that the OS default is in effect. For details refer to your operating system documentation for the SO_SNDBUF socket option. How can I get it in a...

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

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

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

C++ overload << operator for class object acting as stream

So I've browsed a bunch of other threads, but none pertain to the questions I have on this exact topic. I am writing a C++ library to do socket communication. I have a TCP socket class which handles all operations on a TCP socket (setup, read/write, etc). I want to...

No transports available

I recently was trying to upgrade my react-native app to use react-native 0.5.0 and firebase. According to this article the react-native sockets are working and the full firebase sdk should be available. I was previously using firebase-debug and @badfortrains react-native fork with success following the example project Since upgrading...

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

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

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

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

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

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

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

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

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

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

My simple client crash everytime it tries to connect to my python socket server

My client crash everytime it tries to connect to my python socket server. I dont know why but but my server seams to start up fine then when i start up my client it establishes a connection to the server but it crash direct. Im doing almost as what they...

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

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();...

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?

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

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)

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

Datanode and Nodemanager on slave machine are not able to connect to NameNode and ResourceManager on master machine

I have installed hadoop on two node cluster- Node1 and Node2. Node1 is master and Node2 is slave. Node2's datanode and Nodemanager are not able to connect Namenode and Resourcemanager on Node1 respectively. However Node1's datanode and Nodemanager are not able to connect Namenode and Resourcemanager on Node1. Node1: jps...

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

Refactor an IO recursive loop into a monad folding in Haskell

I writing a tcp server, and here's my main loop method: serverLoop :: Socket -> IO () serverLoop sock = do (conn, _) <- accept sock forkIO $ handleConn conn serverLoop sock (Note: handleConn :: Socket -> IO () is a function specific to my program.) I would like to...

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

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

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

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