tcpsocket

How to maintain the TCP connection using Ruby?

邮差的信 提交于 2019-12-13 06:22:16
问题 Using TCPSocket , I need to socket.puts "foobar" , and then socket.close to let the socket in the other side socket.read the message. Is there a way to send or receive a message though a socket, but without closing the socket, which mean I can send message again without creating a socket again? p.s Something like websocket 回答1: If you traverse up the super class chain you will eventually see that you inherit from IO. Most IO objects, in Ruby, buffer the data to be more efficient writing and

Inconsistent tcp_socket behavior in Erlang

穿精又带淫゛_ 提交于 2019-12-13 06:18:13
问题 In order to read input 1 character at a time, I wrote a c program that uses ssty raw . I use this character.c program to call an erlang file, naive_tcp.erl which sends a message over socket to a listening server on the same machine. I expect this server, naive_tcp2.erl , to write back with 26 lines of descending integers and an 80 character long string with 2 "|" pipes in it, so that it lines up on the 80x26 terminal. What happens instead is very inconsistent printing of data. Running .

PHP receiving data from TCP socket repeatedly

会有一股神秘感。 提交于 2019-12-12 23:51:46
问题 The idea is to connect PHP webpage and C program via TCP socket so, that webpage waits for connection from C program and receives data as soon as connection established. The code of PHP socket connection and data receiving is below: PHP(socketRead.php): $address = 'localhost'; $port = 5001; if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) { echo "Socket creation error"; } else { echo "Socket created <br/>"; } if (($ret = socket_bind($sock, $address, $port)) < 0) { echo "Host

TCP Socket Programming in iOS. Server Client Response

僤鯓⒐⒋嵵緔 提交于 2019-12-11 17:57:17
问题 I'm almost done with this task but i'm stuck a point due to which i'm getting partial result. I have server(linux or windows) and client(iOS) between which TCP IP socket connection exist. I have used form load in my iphone simulator where the connection between server and iphone happens automatically as the application opens. Server send the data back what ever I send on simulator and print it in log. But i'm not able to exactly receive the whole response. For "Innovations" I receive maybe

tcp client in vb.net not receiving the entire data response data from server

℡╲_俬逩灬. 提交于 2019-12-11 07:48:17
问题 I have a small program which is a tcp client. I send a string from this client to a device over ethernet (it acts as the tcp server). As soon as the device recieves the input string it will respond back with response data. My problem is i am not getting the entire response data back from the server. (device). Dim serverStream As NetworkStream = clientSocket2.GetStream() Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("my-cmd") serverStream.Write(outStream, 0, outStream.Length)

Ruby TCPSocket / HTTP request

萝らか妹 提交于 2019-12-06 13:24:53
I just started with TCPSockets. I am simply trying to get the google home page. This is my code: require 'socket' host = 'http://www.google.com' port = 80 s = TCPSocket.open host, port s.puts "GET / HTTP/1.1\r\n" s.puts "Host: Firefox" s.puts "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" s.puts "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" s.puts "\r\n" while line = s.gets puts line.chop end s.close This returns: HTTP/1.1 302 Document has moved Location: http://92.242.140.29/?nxdomain=http%3A%2F%2Ffirefox&AddInType=2&PlatformInfo=pbrgen Why? My goal is to get the

Ruby TCPSocket: Find out how much data is available

半世苍凉 提交于 2019-12-03 16:20:16
Is there a way to find out how many bytes of data is available on an TCPSocket in Ruby? I.e. how many bytes can be ready without blocking? The standard library io/wait might be useful here. Requring it gives stream-based I/O (sockets and pipes) some new methods, among which is ready? . According to the documentation , ready? returns non-nil if there are bytes available without blocking. It just so happens that the non-nil value it returns it the number of bytes that are available in MRI . Here's an example which creates a dumb little socket server, and then connects to it with a client. The

TCP keep_alive does not work if you switch off wifi to cause an abrupt connection loss

荒凉一梦 提交于 2019-12-02 20:03:02
问题 Scenario: I have a client and server written using boost::asio 1.63. I am using keep_alive feature in tcp sockets to detect connection losses. Following is the keep_alive code setup. boost::asio::io_service ioService; boost::asio::ip::tcp::socket mySocket(ioService); #ifdef __APPLE__ unsigned int timeoutMillis = 2000; struct timeval tvs; tvs.tv_sec = timeoutMillis / 1000; tvs.tv_usec = (timeoutMillis % 1000) * 1000; if (setsockopt(mySocket.native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tvs,

How do I convert a 24-bit integer into a 3-byte array?

可紊 提交于 2019-12-02 03:29:10
问题 Hey Im totally out of my depth and my brain is starting to hurt.. :( I need to covert an integer so that it will fit in a 3 byte array.(is that a 24bit int?) and then back again to send/receive this number from a byte stream through a socket I have: NSMutableData* data = [NSMutableData data]; int msg = 125; const void *bytes[3]; bytes[0] = msg; bytes[1] = msg >> 8; bytes[2] = msg >> 16; [data appendBytes:bytes length:3]; NSLog(@"rtn: %d", [[[NSString alloc] initWithData:data encoding

data send by firefox tcp socket.send() can't retrive until close the socket

不羁岁月 提交于 2019-12-01 12:54:49
I'm trying to send some data from Firefox to java desktop application .so my java class work as a server and Firefox script work as a client .when i test it using another java class which is client.java data successfully sent to server.java how ever when i use this firefox script to send data ,it actually connect to the server .but send("text"); doesn't work realtime .i mean sever shows received data when i close the socket socket.close(); . but i know there is no problem with server.java code. this doesn't work setTimeout(function(){socket.send("i'm firefox");},5000); // because socket isn't