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

Visual Basic.net Winsock?

Started by Dwarrior333 Apr 12, 2007 at 12:33 PM 8 replies 2.1k views
Original Post
Dwarrior333
Dwarrior333
I am new here, but I have been programing for a few years and was interested in making a network game. I know the core languages (VB, C++, Java, ect.) and I prefer to use Visual BASIC and I switched to .net this year. I was reading the faq and it suggests the I should use Winsock instead of the Direct X. Looking at the suggested tutorials and book samples(on Google books) I have only seen C++ being used. My questions are: Is there a way that I can make a network game using VB.net? If so is there any good tutorials? Should I switch to mainly using C++?
Sirisian
Sirisian
yah I made a small VB.NET multiplayer game before and it is definately possible. The .NET framework has built in networking systems that can be used. They are in System.net namespace I believe. If you are good at programming it takes only a couple of hours to set up a simple server and client system.

MSDN has tutorials that might be able to help.

It's been over a year since I made this:
www.sirisian.templarian.com/mmo_udp_vbnet.zip but it has a simple system. I believe I used a thread system for sending. Not sure, I forgot most of what I learned from it. :/ That version probably won't even run...

May I ask what kind of game you are making. Number of players? I used an OpenGL component to render and the only real reason I used .NET was for the GUI.
Antheus
Antheus
Can you make it? Yes.

Everything else is a matter of personal experience and, often, purism. Most will quickly point out that "VB sux for games and you should use C++ which is the only language capable of game development".

Winsock and DirectX are not related. Winsock is windows implementation of socket library (the networking stack), whereas DirectX refers to a large set of high-performance mostly multi-media APIs, some of which include networking (which in turn uses Winsock implementation).
Dwarrior333
Dwarrior333
@Sirisian: I am not sure yet how many players because I wasn't sure if it was possible with VB.net.
I looked at your program and I wasn't really sure how to use it but Ill look at the code for both programs a little more.
I am not really sure what you mean when you say you use both OpenGL and VB.net together.

@Antheus: I was actually referring to DirectPlay when I said DirectX. I prefer to use VB.net for games but I guess I never tried C++ except for Allegro which I really didn't like very much
hplus0603
hplus0603
VB.NET can do pretty much anything on Windows, as it talks to the .NET framework just like C#. You can write UDP or TCP networking code, using either the raw Socket interfaces, or using the wrapper classes that are in the framework.

You can also use a .NET networking library, something such as "lidgren."
enum Bool { True, False, FileNotFound };
Dwarrior333
Dwarrior333
Thanks

I tried the wiki and I followed the examples and I made the client its own class and everything works fine until I put in the example code:
(note: this is not my exact code because I used a client object and used its send method)
Send("GET / HTTP/1.1" & vbNewLine & "Host: www.google.com" & vbNewLine & vbNewLine)

The error is:
Value of type 'String' cannot be converted to '1-dimensional array of Byte'.

I can see where this is coming from because the first parameter of the send method is a byte array.
Public Sub Send(Data() as Byte)     Dim State as New StateObject()     mySocket.BeginSend(Data, 0, Data.Length, Sockets.SocketFlags.None, addressof EndSend, State) End Sub

Does anyone know what I am doing wrong?
Sirisian
Sirisian
you can use the binary writer and reader classes. I have been told you can just use them at least.

http://msdn2.microsoft.com/en-us/library/system.io.binarywriter.aspx
http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.aspx

They will have a way to return bytes probably.

you can use strings, but I wouldn't as they are very inefficient for bandwidth. for more information:
http://gpwiki.org/index.php/Binary_Packet

To convert a string to a byte array though:
http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
hplus0603
hplus0603
If you convert to UTF-8, your string will look like an array of bytes.

Also, note that the newline used on the web is CRLF -- two characters. Perhaps that's what you put in your vbNewLine variable.
enum Bool { True, False, FileNotFound };
Dwarrior333
Dwarrior333
Quote:
Also, note that the newline used on the web is CRLF -- two characters. Perhaps that's what you put in your vbNewLine variable.

Isn't vbNewLine a new line in vb not really a variable?

I actually got it to compile but then I realized I skipped a few steps so I went back and did:
        mySocket = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, _ System.Net.Sockets.SocketType.Stream, _System.Net.Sockets.ProtocolType.Tcp)        Dim client As New Client(mySocket)        client.Connect()        client.Recieve()

This complied but gave me a
{"A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied"}

It was part of the receive method.

Has anyone done this tutorial/lesson that knows what I am doing wrong?

[Edited by - Dwarrior333 on April 14, 2007 8:29:36 AM]

Topic Locked

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

Sign in to reply to this topic.