Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

header files

Name: Anonymous 2009-10-11 22:06

So I'm basically making a mini version of IRC, with one server that handles connections from a lot of clients.  Then I decided I would pretty much make my own protocol, with a header attached to every operation.  Every operation, sending text, sending a file, creating/joining a room, would have a header attached to it with details like receiver and sender IDs, time stamp, etc. 

So this sounds nice and all in theory, but I'm absolutely at a loss at how to code this thing.  How would I join the header object to the data object?  concat?  Except I don't know wtf that is.  After a client receives something, how would it separate the header from the data?

And making the header... if I create a new header, decide that its sub-operation is going to be "sending," how do I send it to the file class, have the file class create the sub-op packet, and return it?  It all makes sense conceptually but writing the code is hitting me like a brick wall.

Name: Anonymous 2009-10-11 22:08

fuck header files, just put everything the the main.c.

Name: Anonymous 2009-10-11 22:09

using C#

Name: Anonymous 2009-10-11 22:10

>>2
thats what I had originally, but in order to make it nice and etc, I want to use header files....fffff

Name: Anonymous 2009-10-11 22:10

start by writing an RFC or similar document.
what language are you using, OP?

Name: HAXUS THE JUDGE 2009-10-11 22:15

This thread is awesome.

Name: Anonymous 2009-10-11 22:20

>>5

C#

I already have an RFC-like document, I just don't know how to write it in code...basically it goes a little something like this:

Header:
Main operation ID - byte
Sub operation ID - byte
Receiver ID - string
sender ID - string
time stamp - Date
size of sub op - int

Main operations would be File, Text, Room, Connect, etc
Sub ops would be for example, file send, room create, etc.

The send() method would look like

send(){
    header h = new header
    if subop == 2
        send to file class, creates file subop packet, returns
    p = combine(h, data) //concat?
}
send p


But the problem is I don't know how to write this in actual code

Name: Anonymous 2009-10-11 22:23

>>7
sadly, i don't think there are many C# programmers on /prog/.
but maybe you'll get lucky

Name: Anonymous 2009-10-11 22:38

>>7
I haven't coded in C# in a while, but I've seen some pretty neatly looking frameworks for doing just about what you want (a server for a game, where the clients could join rooms and talk, think about your usual MMO crap):
You had Listener class which accepted clients, a network state class for each client, a class for parsing/handling the packets - where you could register any new handler depending on packet id, and you had a generic Packet class which described the protocol and how to encode each packet, there were also some classes for queueing packets for sending/receiving and some code for blocking/filtering packets (DoS protection/banning clients). Everything as done asynchonously.

Alternatively, you could look at more classical aproaches to this, such as some ircd's source code (Hybrid? - coded in C), or maybe one of those web-servers written in Common Lisp ( like CL-HTTP or Core Server) or C (nginx, lighttpd)...

Name: Anonymous 2009-10-11 22:39

ONE WORD: THE FORCED INDENTATION OF CODE; THREAD OVER

Name: Anonymous 2009-10-11 22:52

I would answer this question to get this shit off the first page, but I can't even make out what the fuck the TC is trying to say.  Are you asking how to combine a header and source file in [b]C#[/b]?

If you just want a header on each thing sent, just write your own definition of what every message needs to contain and which bytes contain what.

Name: Anonymous 2009-10-11 22:55

>>11

that what I mean by a header
I'm asking how to attach my "header" (which is just another object, not a header like in C) to the "data"

Name: Anonymous 2009-10-11 23:06

>>11
He's just asking how to make a server/client for a network protocol he made up.

Name: Anonymous 2009-10-11 23:18

Stick them together.
IHBT

Name: Anonymous 2009-10-11 23:19

>>12
So you have some header data and some body data that you want put together?  If they are strings, just use the + operator in C#.  If they are other data objects, just make an array and put the header in the first half and data in the second half and loop through the array sending it piece by piece.

Name: Anonymous 2009-10-12 0:15

>>15
after I do that, how do I separate them on the receiving side?

Name: Anonymous 2009-10-12 0:16

hahaha im a fag

Name: Anonymous 2009-10-12 0:19

>>16
IHBT

Name: Anonymous 2009-10-12 0:20

maybe there is a serialization library in this c sharp

Name: Anonymous 2009-10-12 0:25

>>18

no seriously i need some help fuck

Name: Anonymous 2009-10-12 0:26

can't you just create an object to hold it all?
i mean, fuck. it's an object oriented language.

Name: Anonymous 2009-10-12 0:28

>>21
How do I separate the header information from the file after I receive it?  Depending on the operation number I have a bunch of switch statements to call the appropriate methods

Name: Anonymous 2009-10-12 0:31

>>22
i assume you look through msdn for string modification functions, regexes, whatever

Name: Anonymous 2009-10-12 0:37

>>22
Make a packet registry where you register your handler(recv) and server packets(send), the handler packet classes can be stored in an array or hashtable keyed on the packet id. Each packet would register itself in the registry (or have the registry register them manually). This will allow you to implement each command separately. You'll also probably want some global state objects to represent whatever you're interacting with, but this is a more generic programming problem than just networking.

Name: Anonymous 2009-10-12 0:42

>>22
Use ANSI C

Name: Anonymous 2010-12-06 11:21

>> 1
How do I re-invented wheels?

Name: Anonymous 2010-12-07 9:30

>>27
It's a good way to learn, as long as >>1 doesn't try to publish it.

Name: Anonymous 2010-12-24 19:28

Name: Anonymous 2010-12-27 21:08

Don't change these.
Name: Email:
Entire Thread Thread List