sockets

Why do I need socketpair() when I have socket() with AF_UNIX?

一曲冷凌霜 提交于 2021-02-08 07:39:42
问题 What confuses me is that given that sockets are bi-directional, why can't I just open 1 socket with socket() on the client and one on the server and let them communicate over this single socket? What would be a common use case that I would need a pair of sockets? 回答1: So what is the common use case that I would need a pair of sockets? Typically that you want bidirectional communication between a parent and child process (or sometimes between threads in the same process). It's like a

smart pointer to manage socket file descriptor

三世轮回 提交于 2021-02-08 07:14:39
问题 A smart pointer clears the memory if the pointer gets out of scope. I wanted to adapt this to a file descriptor, like a socket. There you need a user defined deleter, because close() is the function to free the file descriptor (fd) resources. I found this useful page, unfortunately, most approaches did not work for me. Below is a working solution I found up to now, which is a little nasty. Because uniqu_ptr expects a pointer I created int *fd to store the fd value, therefore, I had to close(

C++ recv() problem

怎甘沉沦 提交于 2021-02-08 06:47:47
问题 I want to send a string "Hello there", but I only get "re". Why is that? void Accept() { SOCKADDR_IN sock; int intsock = sizeof(sock); remoteSocket = ::accept(desc, (LPSOCKADDR)&sock, &intsock); if(remoteSocket == -1) { cout << "Error in Accept()" << endl; } HandleConnection(); } void HandleConnection() { cout << "You are connected !!!" << endl; char* temp = new char[20]; Recv(temp); cout << temp << endl; } void Send(const char* buffer) { if((::send(remoteSocket, buffer, strlen(buffer), 0)) <

C++ recv() problem

谁说我不能喝 提交于 2021-02-08 06:47:05
问题 I want to send a string "Hello there", but I only get "re". Why is that? void Accept() { SOCKADDR_IN sock; int intsock = sizeof(sock); remoteSocket = ::accept(desc, (LPSOCKADDR)&sock, &intsock); if(remoteSocket == -1) { cout << "Error in Accept()" << endl; } HandleConnection(); } void HandleConnection() { cout << "You are connected !!!" << endl; char* temp = new char[20]; Recv(temp); cout << temp << endl; } void Send(const char* buffer) { if((::send(remoteSocket, buffer, strlen(buffer), 0)) <

Python(Server) Android(Client) Socket Programming

∥☆過路亽.° 提交于 2021-02-08 05:14:13
问题 I'd like to make a program which connects Python code with Android Studio. But there has been a problem on android studio which is not showing any UI that I'd like to show on Emulator Screen. I think it is due to "StrictMode". But If I except the StrictMode Code. The Program is stopped. What should I do? Here is the codes. Python Code(Server) import socket import random as r HOST = "localhost" PORT = 9999 x = ['10', '20', '30', '40', '50'] y = ['-10', '-20', '-30','-40', '-50'] rssi = ['1.5',

Python(Server) Android(Client) Socket Programming

瘦欲@ 提交于 2021-02-08 05:13:23
问题 I'd like to make a program which connects Python code with Android Studio. But there has been a problem on android studio which is not showing any UI that I'd like to show on Emulator Screen. I think it is due to "StrictMode". But If I except the StrictMode Code. The Program is stopped. What should I do? Here is the codes. Python Code(Server) import socket import random as r HOST = "localhost" PORT = 9999 x = ['10', '20', '30', '40', '50'] y = ['-10', '-20', '-30','-40', '-50'] rssi = ['1.5',

C++ Disable Delayed Ack on Windows

别说谁变了你拦得住时间么 提交于 2021-02-08 04:56:32
问题 I am trying to replicate a real time application on a windows computer to be able to debug and make changes easier, but I ran into issue with Delayed Ack. I have already disabled nagle and confirmed that it improve the speed a bit. When sending a lots of small packets, window doesn't ACK right away and delay it by 200 ms. Doing more research about it, I came across this. Problem with changing the registry value is that, it will affect the whole system rather than just the application that I

UDP non-blocking socket on a real-time OS: sendto() and recvfrom() can return with partial message?

百般思念 提交于 2021-02-08 04:38:47
问题 This is my first message here. I'm working with a non-blocking UDP socket on a real-time OS (OnTime and VxWorks). I have read the documentation and some forums but I have some doubts about 'atomicity' of sendto() and recvfrom() functions: sendto() returns the number of bytes enqueued or error. Is it possible that it's less then the input buffer length? Maybe the output buffer has not enough free space and just few bytes are enqueued... recvfrom() returns the number of byte received or error.

Binary file transfer over Socket using TCP

不羁岁月 提交于 2021-02-08 03:48:56
问题 I am working on a binary file transfer program in which the client has to upload a file to server. For this case, I need to send the file name first and file content second. But this is not feasible for me. Lets see the code: // Client-side code to send file name void sendFileName( int sd, /*Socket Descriptor*/ char *fname) /*Array Containing the file name */ { int n , byteswritten=0 , written ; char buffer[1024]; strcpy(buffer , fname); n=strlen(buffer); while (byteswritten<n) { written

Huge size(in bytes) difference between pickle protocol 2 and 3

筅森魡賤 提交于 2021-02-08 03:47:34
问题 The streamer side keeps sending a sound sample of 2048 bytes along with the time as an integer, together in a tuple that gets pickled using pickle.dumps, and then its send in an UDP packet to the receiver, who then unpickles it, buffers it and then plays the sound sample. Everything was fine using python 3, the bits/seconds speed on the receiver were expected. When I runned the streamer in python 2.7, the speed was faster! I tough python 2 was somehow faster. Then I checked with wireshark the