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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.