Author | Message | Time |
---|---|---|
FrostWraith | OK. Well I have created my first client written purely in C that can connect to servers and such. I have decided that making it connect to BNET and BNLS are good practice servers for me. The problem is I don't have anything like a packet buffer or ways to modify the data to be sent. It's not that I can't write some crude code, I just don't know an efficient way to do it in C. In my opinion, for each packet, I would construct a struct. Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of. It is just purely inexperience with the language. Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits. I want to know if their are any libraries to assist with this. One last thing is whether or not I should be doing connect() or WSAConnect(). Which is more up to date? Which is better and for what reasons? Please post even if you don't have an all out explanation. I just would like to learn this all piece by piece. Thank you. | March 23, 2008, 4:03 PM |
BreW | [quote author=FrostWraith link=topic=17406.msg177229#msg177229 date=1206288225] OK. Well I have created my first client written purely in C that can connect to servers and such. I have decided that making it connect to BNET and BNLS are good practice servers for me. The problem is I don't have anything like a packet buffer or ways to modify the data to be sent. It's not that I can't write some crude code, I just don't know an efficient way to do it in C. In my opinion, for each packet, I would construct a struct. [/quote] A struct? are you sure about that? And what about variable length strings? :d [quote] Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of. It is just purely inexperience with the language. [/quote] If you'd like, I can PM you my packetbuffer.c. [quote] Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits. I want to know if their are any libraries to assist with this. [/quote] I'm not sure I can say that i know what you're talking about, but if you want to get rid of the high and low bits, then what's stopping you from NANDing them out? "dword &= ~(0x80000001);" [quote] One last thing is whether or not I should be doing connect() or WSAConnect(). Which is more up to date? Which is better and for what reasons? [/quote] I personally use connect(), since WSAConnect calls it down the road anyway. WSA* functions are just lame wrappers for the winsock api. They don't do anything too special. | March 23, 2008, 4:27 PM |
FrostWraith | I would definitely be interested in seeing how you formed your packet buffer. Thanks for the reply. I am used to programming in a lot of languages where much is handed to you so I am not used to having to do it all myself :P. | March 23, 2008, 4:36 PM |
NicoQwertyu | [quote author=FrostWraith link=topic=17406.msg177229#msg177229 date=1206288225] One last thing is whether or not I should be doing connect() or WSAConnect(). Which is more up to date? Which is better and for what reasons?[/quote] AFAIK, WSAConnect() supports more options at connection time, such as a QoS request and some connect data used for legacy protocols such as DECNet and OSI TP4. For what you're doing, use connect(). If you want to read more, the link to the MSDN page is here. | March 23, 2008, 8:26 PM |
FrostWraith | Thank you once again for your code brew, but I am trying not to copy, so here is my dilemma. So far since the packet have been small, this has worked, but if I were to write larger packets, how would this do? memset(sendbuffer, (unsigned short)(pbufferlen), 1); I am trying to write a WORD typed variable into the first two bytes of the string to be sent. Since I have only tested on REQUESTVERBYTE on bnls, the packer size has only been 7. Will this work if we start getting into larger packets? | March 25, 2008, 3:05 AM |
NicoQwertyu | [quote]void * memset ( void * ptr, int value, size_t num ); <cstring> Fill block of memory Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).[/quote] The size of the packet shouldn't make a difference. Isn't a WORD two bytes though? Would you want: memset(sendbuffer, pbufferlen, 2);? | March 25, 2008, 4:06 AM |
l2k-Shadow | [quote author=FrostWraith link=topic=17406.msg177257#msg177257 date=1206414322] Thank you once again for your code brew, but I am trying not to copy, so here is my dilemma. So far since the packet have been small, this has worked, but if I were to write larger packets, how would this do? memset(sendbuffer, (unsigned short)(pbufferlen), 1); I am trying to write a WORD typed variable into the first two bytes of the string to be sent. Since I have only tested on REQUESTVERBYTE on bnls, the packer size has only been 7. Will this work if we start getting into larger packets? [/quote] [code] *(WORD*)(sendbuffer + 2) = pbufferlen [/code] | March 25, 2008, 4:12 AM |
FrostWraith | Thanks, I got this ultimately to work with [code] *(unsigned short *)(sendbuffer) = (unsigned short)(pbufferlen); [/code] I wrote some code that would need both bytes and it matched across other languages. Thanks again. | March 25, 2008, 11:32 AM |
UserLoser | [quote author=FrostWraith link=topic=17406.msg177229#msg177229 date=1206288225] OK. Well I have created my first client written purely in C that can connect to servers and such. I have decided that making it connect to BNET and BNLS are good practice servers for me. The problem is I don't have anything like a packet buffer or ways to modify the data to be sent. It's not that I can't write some crude code, I just don't know an efficient way to do it in C. In my opinion, for each packet, I would construct a struct. Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of. It is just purely inexperience with the language. Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits. I want to know if their are any libraries to assist with this. One last thing is whether or not I should be doing connect() or WSAConnect(). Which is more up to date? Which is better and for what reasons? Please post even if you don't have an all out explanation. I just would like to learn this all piece by piece. Thank you. [/quote] Not sure how picky you are on C vs C++ personally who cares: http://www.valhallalegends.com/pub/BC4/Prerelease/BinaryChat4SDK.zip See StoreBuffer.h and ParseBuffer.h. I use a system that is almost exact to that | March 26, 2008, 8:21 PM |