sockets , Python sockets will not connect


Python sockets will not connect

Question:

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 = '0.0.0.0' #Also tried '', 'localhost', gethostname()

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


print "Connected."

My client is:

import socket

host =  '127.0.0.1' #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 (10.0.63.40) 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

Answer:

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

Listening on 0.0.0.0 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 10.0.63.40. That means you should end up calling s.connect("10.0.63.40", 12345).


Related:


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

Refactor an IO recursive loop into a monad folding in Haskell


sockets,haskell,network-programming,io-monad
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...

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

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

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

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?

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

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

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

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

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

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

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


java,apache,sockets,hadoop,tcp
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...

Jetty Web Socket Timeout


javascript,sockets,websocket,jetty
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..." + event.data); } ws.onclose = function(event) { console.log("onclose called..." +...

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

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

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

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


java,multithreading,sockets,messenger,instant
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...

How to choose zmq maximum buffer size properly?


c++,c,sockets,zeromq
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...

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

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

Reading packets from a client stops after 1 or 2 received


c,linux,sockets,server
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...

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

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

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

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

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

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

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

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


python,sockets,python-3.x,serversocket
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...

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

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

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

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

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++ overload << operator for class object acting as stream


c++,sockets,tcp,operators
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...

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

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

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

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

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

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

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?

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

No transports available


sockets,firebase,react-native
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 https://github.com/badfortrains/wsExample. Since upgrading...

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

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

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