What happens if I have one socket, s, there is no data currently available on it, it is a blocking socket, and I call recv on it from two threads at once? Will one of the threads get the data? Will both get it? Will the 2nd call to recv return with an error?
...
What I am trying to do is use the Detours library to hook into an applications WinSock2 send() and recv() functions (a packet logger).
While it does work for the send() function, it does not, however, work for the recv() function.
Here is my relevant code:
#include <cstdio>
#include <ctime>
#include <fstream>
#include <iomanip>
#inclu...
Here's a simplified version of some code I'm working on:
void
stuff(int fd)
{
int ret1, ret2;
char buffer[32];
ret1 = recv(fd, buffer, 32, MSG_PEEK | MSG_DONTWAIT);
/* Error handling -- and EAGAIN handling -- would go here. Bail if
necessary. Otherwise, keep going. */
/* Can this call to recv fail, setti...
Ok, if you look at some of my previous questions, I've been working on getting a simple connection up and running with C sockets (I'm still fairly new to the whole networking aspect of an program, but everyone has to start somewhere, right?). I've included the code below that I have so far and when I execute it, I get no errors, but at t...
Hi
I am trying to pass whole structure from client to server or vice-versa. Let us assume my structure as follows
struct temp {
int a;
char b;
}
I am using sendto and sending the address of the structure variable and receiving it on the other side using the recvfrom function. But I am not able to get the original data sent on the...
Hi, I need some help writing an http client. The trouble comes when I try to receive data from a webserver. The recv() call blocks the program. Any better direction would be extremely helpful, I'll post my code below:
if ( argc != 2 )
{
cerr << "Usage: " << argv[0];
cerr << " <URI>" << endl;
return 1;
}
else
{
uri_string = argv[1...
Hi,
I am using socket to send data from local machine to remote in TCP, stream mode.
The code in the local side is :
// ----------- Local
send(sd, pData, iSize, 0); // send data
The size of the data is about 1Mb, so socket might divide it to several packets.
While I am recieving the data on remote side, I have to recieve the data se...
Hi Alls,
Im using the SocketServer module for a tcp server.
I'm experiencing some issue here with the recv() function, because the incoming packets always have a different size, so if i specify recv(1024) (i tried with bigger value, and smaller), it get stock after 2 or 3 requests because the packet length will be smaller (i think), and...
In winsock, both the sync recv and the async WSARecv complete as soon as there is data available in a stream socket, regardless of the size specified (which is only the upper limit). This means that in order to read a fixed number of bytes from the stream, there should be applied some custom buffering. And unless each read is buffered se...
hey guys,
i have a proxy server running on my local machine used to cache images while surfing. I set up my browser with a proxy to 127.0.0.1, receive the HTTP requests, take the data and send it back to the browser. It works fine for everything except large images. When I receive the image info, it only displays half the image (ex.: the...
I have to implement an HTTP server for a class in C++, but after a connection is accepted, recv() just returns -1. I posted my code belowe, if anyone could help it would be much appreciated.
int main( int argc, char* argv[] )
{
// Interpret the command line arguments
unsigned short port = 8080;
char* base_directory = NULL;
bas...
I have created a raw socket which takes all IPv4 packets from data link layer (with data link layer header removed). And for reading the packets I use recvfrom.
My doubt is:
Suppose due to some scheduling done by OS, my process was asleep for 1 sec. When it woke up,it did recvfrom (with number of bytes to be received say 1000) on this r...
This code sends and recv s txt file perfectly but cannot do it to otehr formats like .exe or .img. Please help me with these as I need to use htonl or htons??
Take a look!!
Here is the server side recv function ::
if (socket_type != SOCK_DGRAM)
{
fi = fopen (final,"wb");
retval = recv(msgsock, ...
Hi all;
Below is the code fragment I have issue with socket programing. Here after select call, If I do not put a sleep on line 9, on Windows XP, 1 byte is received on line 11 (instead 4 byte is sent from server as integer), when I check xmlSize, it is set to 0. Because iResult is 1, execution continues and on line 15 second receive is c...
So, I have the following code:
def LSCPHandler.send_message(message, hostname, port)
s = TCPSocket.open(hostname, port)
s.print message
ret = s.recv(1024)
s.close
LSCPHandler.parse_error(ret)
return ret
end
Which works just fine, normally. The server I'm talking to returns the response pretty quickly, usually, and all is well.
...
Hello! I was trying to hook a custom recv() winsock2.0 method to a remote process, so that my function executes instead of the one in the process, i have been googling this and i found some really good example, but they lack description
typedef (WINAPI * WSAREC)( SOCKET s, char *buf, int len, int flags ) = recv;
Now my question is, wh...
Hello,
I am writing a small C program to understand sockets. What is the maximum length of data returned from recvfrom?
recvfrom(raw, packet_buffer, buf_size, ... );
what is the maximum buf_size in linux. Is there a constant related to this size_t?
Thanks
...
EDIT: the code below has been fixed to receive and send properly AND to account for the actual bytes of messages sent annd recieved (latter thanks to EJP)
Hey guys, I'm programming in C, Unix.
I have server and client that are supposed to exchange msgs. While client seems to send messages fine, server doesn't receive the messages the c...
Pardon if this question has been answered but I couldn't find it.
I'm kinda confused about recv() and recvfrom(). Once the server binds the address (or accepts connection for TCP), recv() is called. Does recv() constantly check for messages that has been sent or does it wait until a message is received? If it does wait, how long is the ...
I'm using the SDL_net sockets API to create a server and client. I can easily read a string buffer, but when I try to send hexadecimal data, recv gets the length, but I cannot seem to be a able to read the buffer contents.
IPaddress ip;
TCPsocket server,client;
int bufSize = 1024;
char message[bufSize];
int len;
server = SDLNet_TCP_Ope...