recv

Receiving data with Winsock

Right now, I'm programming the networking for my online game, and I'm not really sure what to do about receiving data. The problem is that I can't really guess the packet's size, so I thought of reading just 4 bytes from the packet and converting them to an int to know what's the packet's size. Then I'll just create a buffer in that siz...

python socket.recv/sendall call blocking

Hi everyone. This post is incorrectly tagged 'send' since I cannot create new tags. I have a very basic question about this simple echo server. Here are some code snippets. client while True: data = raw_input("Enter data: ") mySock.sendall(data) echoedData = mySock.recv(1024) if not echoedData: break print echoedData server w...

The behavior of send() and recv() in socket communication

The following is the setup: Server Client | | accept connect | | v | send msg1-> | | | v v recv <- send | | v v send msg2-> recv | | v v close He...

while(1) block my recv thread

Hello. I have a problem with this code. As you can see a launch with an internal thread recv so that the program is blocked pending a given but will continue its execution, leaving the task to lock the thread. My program would continue to receive the recv data socket new_sd and so I entered an infinite loop (the commented code). The prob...

C socket programming: calling recv() changes my socket file descriptor?

Hey all, I have this strange problem with recv(). I'm programming client/server where client send() a message (a structure to be exact) and server recv() it. I am also working with multiple sockets and select(). while(1) { readset = info->read_set; info->copy_set = info->read_set; timeout.tv_sec = 1; timeout.tv_usec =...

realloc()ing memory for a buffer used in recv()

I need to recv() data from a socket and store it into a buffer, but I need to make sure get all of the data so I have things in a loop. So to makes sure I don't run out of room in my buffer, I'm trying to use realloc to resize the memory allocated to the buffer. So far I have: // receive response int i = 0; int amntRecvd = 0; char *...

Sockets and multithreading

Hi to all! I have an interesting (to me) problem... There are two threads, one for capturing data from std input and sending it through socket to server, and another one which receives data from blocking socket. So, when there's no reply from server, recv() call waits indefenitely, right? But instead of blocking only its calling thread, ...

recv returns old data

This loop is supposed to take data from a socket line by line and put it in a buffer. For some reason, when there is no new data to return, recv returns the last couple lines it got. I was able to stop the bug by commenting out the first recv, but then I cant tell how long the next line will be. I know it's not a while(this->connected)...

python socket.socket.recv with hidden input

Is there any way to have socket.socket.recv run with hidden input. For example, if I was asking for a password I would want the input to be hidden, as if I were running the "sudo" bash command. Edit: socket.socket.recv asks for data on the remote end. When you are connected to the server it will ask you for text and when you type it in i...

recv overwrite a char[]

Hi all, I'm trying to make a little client-server script like many others that I've done in the past. But in this one I have a problem. It is better if I post the code and the output it give me. Code: #include <mysql.h> //not important now #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #includ...

Python : How to close a UDP socket while is waiting for data in recv ?

Hello, let's consider this code in python: import socket import threading import sys import select class UDPServer: def __init__(self): self.s=None self.t=None def start(self,port=8888): if not self.s: self.s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.s.bind(("",port))...

How do I abort a socket.recv() from another thread in python?

I have a main thread that waits for connection. It spawns client threads that will echo the response from the client (telnet in this case). But say that I want to close down all sockets and all threads after some time, like after 1 connection. How would I do? If I do clientSocket.close() from the main thread, it won't stop doing the recv...

What value will recv() return if it receives a valid TCP packet with payload sized 0

In TCP socket programming, if recv() returns 0, it is taken as an indication that the other side closed its connection. However, AFAIK, the TCP RFC does not mandate the payload of TCP to be > 0. So, theoretically, a TCP stack can receive a message with payload 0. So, essentially my question is what will recv() returns if it receives a p...

SimpleXmlRpcServer _sock.rcv freezes after thousands of requests

Hi there, I'm serving requests from several XMLRPC clients over WAN. The thing works great for, let's say, a period of one day (sometimes two), then freezes in socket.py: data = self._sock.recv(self._rbufsize) _sock.timeout is -1, _sock.gettimeout is None There is nothing special I do in the main thread (just receiving XMLRPC calls)...

Socket programming in Perl

What is the best way to receive data from a socket in Perl, when the data length is unknown? Right now, I read one character at a time in a loop, until I reach the '\0' character. Is there a better way to do this? ...

is it safe to recv() and send() on one socket concurrently?

I remember having read somewhere that a socket can be regarded as two independent half-duplex channels. Does it mean that recv() and send() of the same socket are actually irrelevant? if so, is it by definition or implementation-specific? if not, how the two interfere with each other? thanks. ...

Ending "recv()" loop when all information is Read using Winsock

Hey everyone, I am having an issue in my recv() loop for winsock. I am trying to terminate the loop when iResult==0, however, the loop only ends when the socket closes. It appears to be hanging at the very last recv() where iResult would equal 0. So any ideas on how to terminate the loop effectively? My ultimate goal (whether iResult ==...

Download HTTP thru sockets (C)

Hi, Recently I started taking this guide to get myself started on downloading files from the internet. I read it and came up with the following code to download the HTTP body of a website. The only problem is, it's not working. The code stops when calling the recv() call. It does not crash, it just keeps on running. Is this my fault? Am ...

how to address portion of an (1-D) array?

Hi, I'm a new user to C programming. I've tried researching this online, but couldn't find an answer... how to I access a portion of an array in C? For example, int Data[4] int Input[32] What's the syntax for doing: Data = Input[12:15] such that Data[0] = Input[12] Data[1] = Input[13] Data[2] = Input[14] Data[3] = Input[15] In rea...

I must be running into a buffer limit somewhere receiving data from TCP socket using recv( )

Hi, I'm downloading 6kB of data from a test instrument connected via TCP socket. I'm using SOCK_STREAM: if((MySocket=socket(PF_INET,SOCK_STREAM,0))==-1) exit(1); I haven't set the any buffer sizes, so I assume I'm using whatever the default is. I'm having a problem with receiving data. Here's the statement: if((recv(MySocket, &YRa...