I am trying to send a structure via tcp/ip,i dont know if i am doing it good,it prints a strange chaarcter in my screen.Here is my code that i am using to send and recv:

void Send(const void* buffer, int size)
		int n;
		if((n = ::send(desc, (char*)&buffer, size, 0)) < 0)
			cout << "Error in Send()" << endl;
		cout << n;

	void Recv(void* buffer, int size) {
	    size_t n = 0;
	    n = ::recv(remoteSocket, (char*)&buffer, size, 0);

struct packet {
	unsigned char version;
	unsigned char nMethods;
	unsigned char methods[255];

packet p;
	p.version = SOCKS_VER;
	p.nMethods = 4;
	p.methods[0] = METHOD_AUTH_NO;
	p.methods[1] = METHOD_AUTH;
	p.methods[2] = METHOD_GSSAPI;
	p.methods[3] = METHOD_NO_ACCEPT;

	c.Send((void*)&p, sizeof(p));

PS: it send all 257 bytes,and receives all 257 bytes.

Edited by vbx_wx: n/a

7 Years
Discussion Span
Last Post by gerard4143

You really should use a library like XDR(external data representation) to pass data across a network. It'll ensure that the network byte order is maintained.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.