Skip to main content
GameDev.net gamedev.net
🔒 Locked

Send data packets

Started by DimSum Sep 24, 2002 at 4:01 PM 13 replies 1.2k views
Original Post
DimSum
DimSum
Hi all, I''m new to client-server programming. I''m using Visual Studios C++ as my coding environment. And my question is how do I package a data packet and send it from a client to server??? The data packet that I''m using is just a bunch of strings (CStrings to be more specific). Can anyone tell me where I can get some references and where to start looking?? thanks all. -Phil
kuphryn
kuphryn
I recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.

You should definitely have a good referense on winsock programming especially for Windows.

Kuphryn
mutex
mutex
You can also try to learn just from the WinSock reference. Basically, for the server, you have to:

1. socket() - create a new socket
2. bind() - bind to a port
3. listen() - start listening for incoming connections
4. accept() - accept a new connection. this blocks until someone connects
5. recv() - receive data

For the client:

1. socket() - create a new socket
2. connect() - connect to the server
3. send() - send data

The Platform SDK also had a sample program that used sockets, but it was pretty complicated.

DimSum
DimSum
How about WinInet?? Has anyone had any experience with that?? More particularly through MFC WinInet classes??

-Phil
mutex
mutex
WinInet is an API for higher-level protocols such as HTTP, FTP, Gopher, etc. In your case, you''ll want to use Winsock since you''re doing client/server stuff that doesn''t appear to be tied to any of those protocols.

DimSum
DimSum
I see....
But if I send something to a server I''ll most likely put in an FTP right?? So then wouldn''t I be using those protocols?? I think I''m a little confused. Can you explain?

And when you send something to a server does it always have to be in the form of a file?? Is it possible send a smaller data packet of some kind?? I was thinking about sending small inidividual data packets over to the server verses sending an entire file at once, because then if the connection is interrupted during the tranfer, the server will at least have a part of the file and when the user tries to send again it can just pick up where it left off. (and the data packets are independent of one another as well, they''re just all kept in one file). The data packet that I want to use is just a set of strings.

thanks guys.
DimSum
DimSum
Can anyone comment??

thanks.
smart_idiot
smart_idiot
Packets can contain pretty much anything. FTP is a protocol and is used for transfering files, but you could just as easily define your own protocol.

In Unix pretty much everything is a socket including files, and you can therefore use functions use for reading and writing to files with a socket. If you heard that, and thats what is confusing you, just ignore it. Sockets don''t really have anything to do with files. Basically how this works is one computer sends some data, the other computer stuffs it into a buffer, and you just read the data out of the buffer with recv. I think, I''m fairly new at this.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
DimSum
DimSum
okay,
So let me get this straight... if I use sockets then its basically like the server is a part of the client''s system since there is an open connection between them. So then they can send data back and forth between each other through some program??

Is this how WinSock works too??

thanks.

-Phil
daerid
daerid
Pretty much, yeah. WinSock is just a name for Microsoft''s socket API. Data is sent over a network as packets. What happens is, the server creates a socket and "binds" it to a specific port. Then, it instructs that socket to start listening on that port. That way, when data (or a connection) comes in to the server machine on that port, the socket then notifies the socket subsystem that a connection/data is available on that port.

The server code tells the socket subsystem to surrender the connection/data by calling recvfrom(for UDP sockets)/accept(for TCP sockets).
daerid@gmail.com
owl
owl
i have made a client-server application using vb winsock control, and I realized that the packets I send to the cliend can arrive in different order and even not reach client''s port.

Because of my hurry I was forced to code a queue for output messages and a custom protocol to verify every packet is sent in order and that arrives safely to the client, If not after n seconds I do a resend of that message. I do validate on client side that I haven''t already recieved that message, I use msg-id number to identify them. Do I am a lammer at this? I''m using TCP-IP protocol, not UDP.

I post this, because if this is a common issue to winsock, it could be usefull, and if it isnt it could be usefull to take me as a bad example: "you shouldn''t do like xaxa did". Either way I could learn, so please FLAME ME AS WELL
[size="2"]I like the Walrus best.
Stoffel
Stoffel
Doesn''t TCP guarantee in-order receipt of messages? I read a protocol book on it once but haven''t had to implement it in software so I don''t know the answer personally.
smart_idiot
smart_idiot
I think so.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
daerid
daerid
Yes. The TCP protocol, as one of it''s requirements, is guaranteed packet delivery, and also guaranteed first-send-first-received packet order.
daerid@gmail.com
owl
owl
well, it doesn''t work with VB Winsock Control.

FLAME
FLAME
FLAME
[size="2"]I like the Walrus best.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.