- Viewing Profile: Posts: rnw159
Community Stats
- Group Members
- Active Posts 63
- Profile Views 512
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
User Tools
Contacts
rnw159 hasn't added any contacts yet.
Posts I've Made
In Topic: Anyone want a want a file encrypter I made?
13 January 2012 - 08:35 PM
In Topic: Anyone want a want a file encrypter I made?
13 January 2012 - 08:24 PM
In Topic: Sending and receiving structs (I read FAQ)
05 May 2011 - 07:09 AM
I'm using non blocking because I'm sending game data. If select is what I need then I will look into it. Thanks!
*edit*
I have a new problem. The program works great in terms of successfully sending information. However, there is about a 10 second lag when I'm trying to send realtime information. This is being sent over local 127.0.0.1. The server takes a long time to send the data after it has been received. and the client takes a long time to send the data to the server.
One cause may be if you're sending many small messages over TCP, they may not actually be transmitted until the outgoing stream buffer is of a certain size.
setsocketopt - Check out TCP_NODELAY
Thanks this helped a lot! The problem I have now is that if I continually send data the lag gets greater and greater until I stop sending data for a few seconds. CAn you offer some help on this?
*edit*
Also it gets twice as laggy for every client I add. Any suggestions?
In Topic: Sending and receiving structs (I read FAQ)
04 May 2011 - 09:32 PM
*edit*
I have a new problem. The program works great in terms of successfully sending information. However, there is about a 10 second lag when I'm trying to send realtime information. This is being sent over local 127.0.0.1. The server takes a long time to send the data after it has been received. and the client takes a long time to send the data to the server.
In Topic: Sending and receiving structs (I read FAQ)
04 May 2011 - 09:04 AM
Wow thanks, there are no tutorials for this anywhere. Is this method 100% reliable. I don't understand the part about reading each byte by the integer representing it. Can someone elaborate?I haven't played around with raw win32 sockets for a while as I'm quite fond of the abstraction that boost::asio provides. I do think however it is very important to understand the key underlying concepts as you are doing by working at the lower level so I'll give you some examples. This is from the top of my head without much thinking about it so usual disclaimers apply....
This is an example of sending data... receiving is similar in principle. This probably isn't your problem because sending just 8 bytes is likely to succeed in one call but this is necessary nontheless.// Encapsulating sending a buffer of generic data. Accepts the array of bytes to send // and the number of bytes to send. (True success, all sent, false failure). This is blocking. bool sendData(char *i_buf, int i_bufLen) { int offset = 0; int rc; while (offset < i_bufLen) { rc = send(socket, i_buf+offset, i_bufLen-offset); if (rc == SOCKET_ERROR) return false; offset += rc; } return true; }
Your main concern is converting your data types into a common format supported at your client and server ends. Here is an example of receiving and translating data:char recvData[256]; uint32_t playerX = 0; uint32_t playerY = 0; if (receiveData(recvData, 256)) { // Similar to sendData // We've succesfully read 256 bytes of data, we know that the stream starts with 2 4-byte integers. Read them: // Read each byte into the integer representing the player position (similar to the way I'd do it) playerX = recvData[0] << 24; playerX |= revData[1] << 16; playerX |= revData[2] << 8; playerX |= revData[3]; playerY = recvData[4] << 24; playerY |= revData[5] << 16; playerY |= revData[6] << 8; playerY |= revData[7]; // Or use the helper function for this something like this: // playerX = ntohl(*(uint32_t*)recvData); }
There's a whole lot more I'd recommend doing - think about implementing your own message buffer class that serializes / deserializes different data types into an appropriately encoded byte array.I hope this gives you an idea of what you need to do.
- Home
- » Viewing Profile: Posts: rnw159

Find content