sockets

Linux socket using multiple threads to send

这一生的挚爱 提交于 2021-02-04 13:43:46
问题 I have a single non-blocking socket sending udp packets to multiple targets and receiving responses from all of them on the same socket. I'm reading in a dedicated thread but writes (sendto) can come from several different threads. Is this a safe without any additional synchronization? Do I need to write while holding a mutex? Or, do writes need to come from the same thread and I need a queue? 回答1: The kernel will synchronize access to underlying file descriptor for you, so you don't need a

OSError: [Errno 107] Transport endpoint is not connected

半世苍凉 提交于 2021-02-04 13:02:47
问题 I am trying to learn how to use sockets in python to communicate between two computers. Unfortunately I get this error when everything seem to be right: OSError: [Errno 107] Transport endpoint is not connected Upon googling, I found that this is because the connection may have dropped. But I run both the client and server side of the program in the same machine itself. I tried connecting again from the client end and I get this: OSError: [Errno 106] Transport endpoint is already connected

How to get amount of non-ACK-ed TCP data for the socket?

戏子无情 提交于 2021-02-04 12:22:18
问题 Linux has ioctl SIOCOUTQ described in man-page tcp(7) that returns amount of unsent data in socket buffers. If I understand kernel code right, all the non-ACKed data is counted as "unsent". The ioctl is available at least since 2.4.x. Is there anything alike for {Free,Net,Open,*}BSD, Solaris, Windows? 回答1: There are (at least) two different pieces of information you might want: the amount of data that hasn't been sent yet, and the amount of data that's been sent-but-not-ACK-ed. On Linux:

How to get amount of non-ACK-ed TCP data for the socket?

落爺英雄遲暮 提交于 2021-02-04 12:21:18
问题 Linux has ioctl SIOCOUTQ described in man-page tcp(7) that returns amount of unsent data in socket buffers. If I understand kernel code right, all the non-ACKed data is counted as "unsent". The ioctl is available at least since 2.4.x. Is there anything alike for {Free,Net,Open,*}BSD, Solaris, Windows? 回答1: There are (at least) two different pieces of information you might want: the amount of data that hasn't been sent yet, and the amount of data that's been sent-but-not-ACK-ed. On Linux:

How to do a large text file transfer in python?

☆樱花仙子☆ 提交于 2021-02-04 11:11:00
问题 I'm learning socket programming and python. I need to create a server that accepts a command from client and send a large text file back to the client. The client then saves the complete text file to its directory. In my code, the server is sending the whole text file line by line, but the client could only accept 1024 bytes. I'm not sure what I need to add so the client can receive the whole text file from the server and save it to its directory. Can someone take a look at my code and point

How to do a large text file transfer in python?

血红的双手。 提交于 2021-02-04 11:10:59
问题 I'm learning socket programming and python. I need to create a server that accepts a command from client and send a large text file back to the client. The client then saves the complete text file to its directory. In my code, the server is sending the whole text file line by line, but the client could only accept 1024 bytes. I'm not sure what I need to add so the client can receive the whole text file from the server and save it to its directory. Can someone take a look at my code and point

How to do a large text file transfer in python?

余生长醉 提交于 2021-02-04 11:09:08
问题 I'm learning socket programming and python. I need to create a server that accepts a command from client and send a large text file back to the client. The client then saves the complete text file to its directory. In my code, the server is sending the whole text file line by line, but the client could only accept 1024 bytes. I'm not sure what I need to add so the client can receive the whole text file from the server and save it to its directory. Can someone take a look at my code and point

How to do a large text file transfer in python?

…衆ロ難τιáo~ 提交于 2021-02-04 11:08:12
问题 I'm learning socket programming and python. I need to create a server that accepts a command from client and send a large text file back to the client. The client then saves the complete text file to its directory. In my code, the server is sending the whole text file line by line, but the client could only accept 1024 bytes. I'm not sure what I need to add so the client can receive the whole text file from the server and save it to its directory. Can someone take a look at my code and point

APM, EAP and TPL on Socket Programming

我们两清 提交于 2021-02-04 10:57:42
问题 I found Difference between […]Async and Begin[…] .net asynchronous APIs question but this answer confused me a little bit. Talking about these patterns, Stephen said: Most *Async methods (with corresponding *Completed events) are using the Event-Based Asynchronous Pattern. The older (but still perfectly valid) Begin* and End* is a pattern called the Asynchronous Programming Model. The Socket class is an exception to this rule; its *Async methods do not have any corresponding events; it's

C: send file to socket

孤街醉人 提交于 2021-02-04 10:32:25
问题 I`m trying to send binary file using socket. FILE *file; char *file_data; file = fopen(filepath, "rb"); //Allocate memory file_data=(char *)malloc(fileLen+1); //Read file contents into buffer fread(file_data, fileLen, 1, file); fclose(file); sent = send(client, file_data, strlen(header)+fileLen, 0); It works OK, but some files a too large and I want to read a part to buffer, send it, then read the second part, send it and so on. I tried to get parts using fread and fgets, but i failed =( How