• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Roman Gorkiewicz

How do I send types instead of strings with WinSock (VB)?

12 posts in this topic

In Visual Basic you write... Dim sendStr as String sendStr = "Text" Winsock.SendData sendStr ...to send a text string. How do I send a complete type?
0

Share this post


Link to post
Share on other sites
How do you write complete types to a file? And read them? Sockets are essentially treated as just another file and you send a stream of bytes down them. Do you mean a complete type such as a Class? (I''m not 100% familiar with VB.) Unless Visual Basic has a function to write the object''s binary representation out, and read such an object in at the other end (which I doubt), you''d need to do something like writing out all the important member variables for that object. This would be best done with 2 functions, one Write() which exports the data to a string, and one Read() which takes such a string and initialises an object with it.

Hope that''s some help.
0

Share this post


Link to post
Share on other sites
The Winsock control doesn''t allow you to send user declared types. The best you can do is to send the individual data members one at a time. I would suggest something like this: (syntax may be wrong, it''s been a while since I''ve used VB)


Type SOMETYPE
t1 As Byte
t2 As Currency
t3 As Long
End Type

Sub SendSOMETYPE(d As SOMETYPE)
Winsock.SendData d.t1
Winsock.SendData d.t2
Winsock.SendData d.t3
End Sub
0

Share this post


Link to post
Share on other sites
Speaking from own experiences, Winsock in VB is a bitch to program. Not only is it hard to send data, there is also (as far as I know) no function for seperating the incoming data if it comes in shortly after another data string. That means that if you send two chatstrings, Winsock will return these two in one string.

I solved that by using one character for the beginning of a string and one for the end of a string. Like this:

$Hi!¤$How are you?¤

It makes the interpetation of it slow and time consuming to code, but that's the only way I know. If you really want to use network communication, you should definetly look at DirectPlay, it's really divine compared to Winsock. You can send types, strings, longs and bytes, just about anything you want.

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown

Edited by - Spiff on 3/28/00 2:21:02 AM
0

Share this post


Link to post
Share on other sites
Just send the size of your data as a LONG and then the data.
That''s what DirectPlay does when using TCP.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Spiff

Speaking from own experiences, Winsock in VB is a bitch to program. Not only is it hard to send data, there is also (as far as I know) no function for seperating the incoming data if it comes in shortly after another data string. That means that if you send two chatstrings, Winsock will return these two in one string.


Well, that''s how TCP/IP works in general. It makes no attempt to split up what you send or group it, nor should it, as you may send something in several parts anyway. It just simply sends whatever you tell it, verbatim. If you want to delineate sections, it''s up to you to use some sort of delimiter. For instance, a telnet app in C might call read() (or recv() in Windows, I think) repeatedly, and each time add whatever it gets to an ''incoming'' buffer. The only way it knows it''s read a full line is when it sees a carriage return/line feed, at which point it can clear the buffer up to that point and continue.

Of course, more high level APIs such as DirectPlay may break things up into ''messages'' or something like that, but Winsock is just a nasty wrapper for standard sockets code and does little more than let you treat a socket as another binary file. If you want to use it directly, it''s best to work out your own protocol, or borrow someone else''s, and wrap some buffering functions in a class/object.
0

Share this post


Link to post
Share on other sites
That, I didn''t know. Thank you.

One note though: "Well, that''s how TCP/IP works in general" - don''t you mean Winsock or whatever functions that handles the incoming/outgoing TCP/IP traffic? TCP/IP is only the "delivery guy".

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown
0

Share this post


Link to post
Share on other sites
First, thanks for the replies!

If I use the way of SiCrane to send data, I do not know to what the data belongs.
In my program all the important data is put into a string. Commas are
separating the data pieces. The first value identifies the string.
But accumulating all the data into a string and extracting it later
consumes a lot of time. Is there an easier way to do this, without the risk
of not knowing what data has arrived? In general functions like read and write
need the same treatment like I do with strings. I do not know how DirectPlay
handles this, but DP is far to overheaded for my simple program.
Perhaps someone of you knows where to find a simple example program.
0

Share this post


Link to post
Share on other sites
Well, let''s pretend that you have three types: Type1, Type2, Type3.

You could do the following:


Sub SendType1(data As type1)
Dim id as Byte
id = 1
Winsock.SendData id
Winsock.SendData data.t1
...
End Sub
Sub SendType2(data As Type2)
Dim id as Byte
id = 2
Winsock.SendData id
Winsock.SendData data.t1
...
End Sub
Sub SendType3(data As Type3)
Dim id as Byte
id = 3
Winsock.SendData id
Winsock.SendData data.t1
...
End Sub

Sub ReadData()
Dim id as Byte
Winsock.GetData id, vbByte
If (id = 1) Then
Call GetType1
Else
If (id = 2) Then
Call GetType2
Else
Call GetType3
End If
End If
End Sub



Spiff:
TCP is a stream-oriented transport protocol. It guarantees in-order transmission of data sent. Otherwise it makes no promises. As long as data is received it''s stuffed in the same buffer as all the other data already received on that port, in the same order it was sent. Yes, you can write Application, Presentation or Session layer protocols that will allow discrete messages, but there''s no support for discrete messages in TCP.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Spiff

One note though: "Well, that''s how TCP/IP works in general" - don''t you mean Winsock or whatever functions that handles the incoming/outgoing TCP/IP traffic? TCP/IP is only the "delivery guy".


I guess that technically, you are right. As was I. I was referring to the fact that TCP/IP is just the delivery guy, and makes no effort to do anything with it, therefore by implication, Winsock as a very thin wrapper around it, also does no such higher-level ordering. You really are just writing a stream of bytes to a black hole, and the receiving end has the responsibility to make sense of it all You have to agree some higher-level protocol between server and client, such as Telnet, HTTP, FTP, etc. TCP/IP helps in that it makes sure data is sent at least once, only once, and is ordered. (It may not always arrive in order, but it''s the protocol''s job to re-order it before it reaches your app. Ever noticed your internet connection is receiving data at a high rate, yet your download is not proceeding? Chances are, a packet is missing, and the protocol is buffering subsequent packets until it gets the missing one and can present them in order.)
Anyone interested in learning more should see www.ecst.csuchico.edu/~beej/guide/net/ for a guide to sockets (although I think it''s mainly Unix based.
0

Share this post


Link to post
Share on other sites
In a real-time game, you don''t want the guaranteed message delivery of TCP. I mean, it''s not good to loose a bunch of packets, but if a packet does wander astray in transit, you certainly don’t want to spend time trying to recover that data because by the time you finally receive it you could end up with a player’s location from a few moves/seconds ago. Then what are you going to do with that data?

It’s best just to move on and hopefully get the next packet and then just speculate the path say from move 1 to move 3. This is only for real-time of course not including chat programs. In turn-based games it’s more crucial to receive every packet.
0

Share this post


Link to post
Share on other sites
Thank god for DirectPlay.

Some "fun" TCP/IP reading: http://www.microsoft.com/technet/deploy/tcpintro1.asp

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown
0

Share this post


Link to post
Share on other sites