tcpserver

How to share data between threads in this threaded TCPServer?

蹲街弑〆低调 提交于 2019-12-17 06:46:51
问题 I'm working on a project which involves sending data over TCP. Using the ThreadedTCPServer I'm able to do that already. The server thread only needs to read incoming strings of data and set the value of variables. Meanwhile I need the main thread to see those variables changing value. Here's my code so far, just modified from the ThreadedTCPServer example: import socket import threading import SocketServer x =0 class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler): def handle(self)

How to send a “hello” to server and reply a “hi”?

限于喜欢 提交于 2019-12-14 01:23:16
问题 With my code I can read a message on the server and write from the client. But I am not being able to write a response from the server and read in the client. The code on the client var cli = new TcpClient(); cli.Connect("127.0.0.1", 6800); string data = String.Empty; using (var ns = cli.GetStream()) { using (var sw = new StreamWriter(ns)) { sw.Write("Hello"); sw.Flush(); //using (var sr = new StreamReader(ns)) //{ // data = sr.ReadToEnd(); //} } } cli.Close(); The code on the server

How to allow TCP connections from local host only

我的未来我决定 提交于 2019-12-13 04:53:33
问题 I want to be able to get request on a specific port only from localhost (both from 127.0.0.1 and my_local_ip ); I tried the following: int localhost = (127 << 24) + 1; // 127.0.0.1 sock_address.sin_addr.s_addr = htonl(localhost); This lets me connect only with 127.0.0.1 but not from the actual local ip. I also tried: char hostName[128] = ""; struct hostent *pHost = 0; gethostname(hostName, sizeof(hostName)); pHost = gethostbyname(hostName); memcpy(&sock_address.sin_addr, pHost->h_addr_list[0]

Using Sockets with NSXPCConnection

99封情书 提交于 2019-12-13 04:46:43
问题 Running into an issue when using sockets with an NSXPCConnection. Basically, there is a main process and a helper process running, established via NSXPCConnection. That helper process needs to act as a server and listen to a particular port (say 111), which receives outside connections. The helper process opens a listening socket using the TCPServer helper class (wrapper around CFSocket ) which is provided by Apple. Code found here: https://code.google.com/p/iphone-remotepad/source/browse

How to squeeze in additional parameters to a reaper function when a parent is signalled to kill a child (c)?

纵然是瞬间 提交于 2019-12-13 04:06:35
问题 I'm writing a TCP server that functions very much like a chatroom and came across this question. When a user connects, a child process is created to serve the user. When a user logs in, I store his username into a text file, online.txt But when a user logs out, I need to remove the user from online.txt (PROBLEM), the parent then signals a reaper() and kills the child. My questions are: Q1: How I can squeeze in additional information to the reaper (such as the username that the user used to

Python Asyncio - Server able to receive multi-commands in different times and processing it

删除回忆录丶 提交于 2019-12-13 00:02:32
问题 I am building a client/server communication by using the AsyncIO library in Python. Now I'm trying to make my server able to receive more than one command, process it and reply when done. I mean: Server received the command and can be able to receive "n" more commands while processing the previous received commands. Could someone help me how to find some examples or than how is the best way to make a search? 回答1: I mean: Server received the command and can be able to receive "n" more commands

Ruby TCPServer strange behavior in writing to client

别来无恙 提交于 2019-12-12 02:21:41
问题 I'm creating a Ruby gem named EmeraldCutter which is, essentially, a very simple TCP server. It happens that I detected a very strange behavior and I'd be very glad if someone could give me some clue about this. As you may see by the code below, it starts a new Thread for each request received, grabs the message sent to the server, separate its parameters and stores them in a hash and then writes to the client a list with the elements of this hash in a list of the form key => parameter Then

boost asio async_read: the read message adds to itself

蓝咒 提交于 2019-12-11 22:22:02
问题 I use my PC as a server. The client sends messages like: "PART1:Part2", and the server performs the necessary actions. I use boost's asio for the server code. void start_read() { boost::asio::async_read(socket_, input_buffer_, boost::asio::transfer_at_least(1), boost::bind(&tcp_connection::handle_read, shared_from_this(), boost::asio::placeholders::error)); } // When stream is received handle the message from the client void handle_read(const boost::system::error_code& error) { if (!error) {

TcpListener vs SocketAsyncEventArgs

邮差的信 提交于 2019-12-11 13:48:34
问题 Is there a valid reason to not use TcpListener for implementing a high performance/high throughput TCP server instead of SocketAsyncEventArgs ? I've already implemented this high performance/high throughput TCP server using SocketAsyncEventArgs went through all sort of headaches to handling those pinned buffers using a big pre-allocated byte array and pools of SocketAsyncEventArgs for accepting and receiving, putting together using some low level stuff and shiny smart code with some TPL Data

Distinguish b/w two or more TCP clients in nodejs?

五迷三道 提交于 2019-12-08 09:46:01
问题 isn't there any Unique ID or something for every client? suppose I want use this echo server to echo message received from one client to all connected clients: var net = require('net'); var server = net.createServer(); server.on('connection', function (server_socket) { console.log('client connected'); server_socket.write('hello client! Say something.'); server_socket.pipe(server_socket); server_socket.on('end', function () { console.log('client disconnected'); }); }); server.listen(80,