socketserver

OSError [Errno 99] - python

[亡魂溺海] 提交于 2019-12-31 06:07:04
问题 i want to execute the following simple server code: import socket s = socket.socket() # Create a socket object host = socket.gethostname() # Get local machine name port = 22331 # Reserve a port s.bind((host, port)) # Bind to the port s.listen(5) # Now wait for client connection. while True: c, addr = s.accept() # Establish connection with client. print('Got connection from', addr) c.send('Thank you for connecting') c.close() gives the following error while executing: OSError: [Errno 99]

网络编程和多线程

蹲街弑〆低调 提交于 2019-12-24 15:24:58
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 网络编程Socket 简单例子 服务器端 public class SocketServer { public static void main(String[] args) throws IOException { // 端口号 int port = 7000; // 在端口上创建一个服务器套接字 ServerSocket serverSocket = new ServerSocket(port); // 监听来自客户端的连接 Socket socket = serverSocket.accept(); DataInputStream dis = new DataInputStream( new BufferedInputStream(socket.getInputStream())); DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(socket.getOutputStream())); do { double length = dis.readDouble(); System.out.println("服务器端收到的边长数据为:" + length); double result = length * length

Create a socket in Swift

寵の児 提交于 2019-12-24 01:55:16
问题 I'm trying to write a simple echo server with swift. The examples I found are either non-functional and low-level or written in objective-c. I failed at a lot of things, I will start from the top. I cannot manage to create a simple socket using higher-level functions like CFSocketCreate . This is what I ended up with: class EchoServer : NSObject, NSStreamDelegate { private var serverSocket: CFSocketRef? func start() { self.serverSocket = CFSocketCreate(kCFAllocatorDefault, AF_INET, SOCK

Python socket recv from java client

£可爱£侵袭症+ 提交于 2019-12-23 12:09:40
问题 I have a problem with a simple python tcp server (I'm using SocketServer class) that have to receive data from a java client. Here the server side code: class ServerRequestHandler(SocketServer.BaseRequestHandler): [...] def handle(self): requestCode = struct.unpack('>i', self.request.recv(4))[0] [...] [...] Here there is the client: addr = InetAddress.getByName(hostname); SocketAddress sockaddr = new InetSocketAddress(addr, port); clientSocket = new Socket(); clientSocket.connect(sockaddr,

Only receiving one byte from socket

蹲街弑〆低调 提交于 2019-12-23 09:31:43
问题 I coded a server program using python. I'm trying to get a string but i got only a character! How can I receive a string? def handleclient(connection): while True: rec = connection.recv(200) if rec == "help": #when I put help in the client program, rec = 'h' and not to "help" connection.send("Help Menu!") connection.send(rec) connection.close() def main(): while True: connection, addr = sckobj.accept() connection.send("Hello\n\r") connection.send("Message: ") IpClient = addr[0] print 'Server

Shutting down python TCPServer by custom handler

橙三吉。 提交于 2019-12-22 12:34:38
问题 I'm trying to shutdown a TCPServer from the SocketServer module through a GET request by the client, emitted when the window is closed, however the following code fails to initiate the shutdown: def show_webgl(data): import SocketServer import SimpleHTTPServer from webbrowser import open PORT = 8000 RUNNING = True class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): if self.path=='/atom.json': # return data return elif self.path == '/shutdown': httpd.shutdown() #

Python socket.send() can only send once, then socket.error: [Errno 32] Broken pipe occurred

a 夏天 提交于 2019-12-20 10:37:51
问题 I'm a newbie in network programming, so please forgive me if this is a dumb question :) I created 1 client and 1 SocketServer.ThreadingMixIn server on Ubuntu 10.04.2 using Python2.7, but it seems like I can only call sock.send() once in client, then I'll get a: Traceback (most recent call last): File "testClient1.py", line 33, in <module> sock.send('c1:{0}'.format(n)) socket.error: [Errno 32] Broken pipe Here's the code I wrote: testClient1.py: #! /usr/bin/python2.7 # -*- coding: UTF-8 -*-

TcpListener: How to listen on specific port on all interfaces?

安稳与你 提交于 2019-12-18 05:51:02
问题 There are three overloads for constructing a TcpListener: public TcpListener(int port); ( obsolete ) public TcpListener(IPEndPoint localEP) public TcpListener(IPAddress localaddr, int port) i want to listen on a particular port, but on all available interfaces. There was an overload available to do that, but it's been marked as obsolete . What is the new preferred/non-obsolete way to listen on a particular port on all interfaces with a TcpListener in .NET? For helpfulness sake, an IPEndPoint

SimpleHTTPServer and SocketServer

有些话、适合烂在心里 提交于 2019-12-14 01:40:54
问题 I have created a 'handler' python script as follows: import SimpleHTTPServer import SocketServer PORT = 8000 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print "Serving at port:", PORT httpd.serve_forever() I also have a javascript function, which sends information to the server a URL request. This all works fine, when I run my handler script, and then my javascript, I can see all of the data from the JS in the terminal: localhost

How to send data to a different request from the current request handler? (Python SocketServer with ThreadingMixIn)

拜拜、爱过 提交于 2019-12-14 01:25:36
问题 I'm writing a multiplayer game server and client in Python, using the built-in SocketServer's TCPServer and ThreadingMixIn because it seems easier than manually managing the socket and threading modules. (I'd like to stick with the built-in modules for this.) It uses a protocol similar to HTTP for communication (GTP). Requests involving only one client already work. If a client sends the request " GET /index.html GTP/0.2 ", the server just has to respond " GTP/0.2 200 OK " to that client. But