Tagged: network library
- This topic has 9 replies, 2 voices, and was last updated 11 years, 8 months ago by Anonymous.
-
AuthorPosts
-
March 12, 2013 at 08:33 #471AnonymousInactive
Hi, I’m looking to use networkcomms for a Unity3D project. I’ve looked through the tutorials, and the API, but I’m really having trouble understanding the layout.
I was expecting to find something along the lines of Connect(ip, port) to create a permanent connection from client to server, which would return/throw the usual connection errors or success.
Once established, sending and receiving commands seems relatively straight forward with NetworkComms.AppendGlobalIncomingPacketHandler and SendObject.
Any help would be gratefully received
Marc
March 12, 2013 at 12:11 #472MarcFKeymasterHeya Marc,
Many thanks for your interest in NetworkComms.Net. One of the great things about the library is that it does all of the network/connection management for you. For example if you would like a TCP connection to the ip address 192.168.0.1 on port 10000 you simply retrieve it using:
Connection newConnection = TCPConnection.GetConnection(new ConnectionInfo(“192.168.0.1”, 10000));
The advantage of this approach is that should the connection already exist, regardless where you try to use the connection via TCPConnection.GetConnection() you get the existing connection. If the connection does not already exist then it is created for you. A good demonstration of this usage can be found the in the WPF chat example tutorial, https://networkcomms.net/creating-a-wpf-chat-client-server-application/.
Once you have the connection you can then send as you mention using newConnection.SendObject() etc.
We have had some issues with version 2.1 in unity3d but please download the current alpha version of v2.2 using this temporary link https://networkcomms.net/downloads/NetworkCommsDotNetCompleteDLL_Net2_v2.2.0-Alpha.zip.
If you have any other problems please let us know,
Regards,
MarcMarch 12, 2013 at 19:37 #473AnonymousInactiveThanks for that Marc,
I’m actually looking to set up a UDP connection, as it’s going to be for a game; which means once I can prove the concept to myself, I’ll be needing a license XD.
The 5 parameters for new UDPConnection I’m unsure about. As speed is required, I only want basic DataSerializing – really just send and receive simple strings that I’ve coded myself.
Any help muchly appreciated 🙂
Marc
March 12, 2013 at 20:27 #474MarcFKeymasterFor pure speed, if you are sending small objects you want to use something along these lines:
//Change default send receive options to remove compression
NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions<ProtobufSerializer>();//Create the connection
Connection newConnection = UDPConnection.GetConnection(new ConnectionInfo(“192.168.0.1”, 10000), UDPOptions.None);
newConnection.SendObject(“packetName”, “This is the information I want to send!”);Here we are just sending a string but you might also want to send small structs or classes containing the necessary information. For an example on how to send custom objects checkout the AdvancedSend example in the ExamplesConsole project. You’ll have to download the source zip bundle for that.
Regards,
March 12, 2013 at 22:15 #475AnonymousInactiveThat’s wonderful Marc, thank you. I’m still getting the error “UDPConnections doesn’t contain a constructer that takes 2 arguments”. I’ve worked it out that it’s 5 arguments, but I can’t find any documentation on the constructer’s arguments.
Many thanks
Marc
March 13, 2013 at 07:18 #476MarcFKeymasterHeya Whippets, documentation on all of networkComms.Net should be available via either the online API, https://networkcomms.net/api/ or the downloadable reference, https://networkcomms.net/download/.
Exactly which method is throwing the error “doesn’t contain a constructer that takes 2 arguments”? Also what development environment are you using, i.e. monodevelop, visual studio 2005 express, visual studio 2012 ultimate etc?
March 14, 2013 at 07:29 #479AnonymousInactiveHi,
This is my code (I’m using Unity3D’s own editor).
NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions();
ConnectionInfo conninfo = new ConnectionInfo(ip, System.Int32.Parse(port));
conn = new UDPConnection(conninfo, UDPOptions.None);
It’s this last line causing the grief, with the error “The type ‘NetworkCommsDotNet.UDPConnection’ does not contain a constructor that takes ‘2’ arguments”
Many thanks,
Marc
March 14, 2013 at 07:31 #480AnonymousInactiveThis forum has stripped my angle bracket ProtobufSerializer angle bracket from the first line of the code, but it is there
Marc
March 14, 2013 at 09:02 #481MarcFKeymasterAh, you are not using the correct method.
You are using
conn = new UDPConnection(conninfo, UDPOptions.None);
you should be using
conn = UDPConnection.GetConnection(conninfo, UDPOptions.None);
note, this is a static method so no ‘new’ statement. It’s implemented in this was so that if a connection already exists with the provided connectionInfo the existing connection can be returned instead.
Marc
March 15, 2013 at 06:51 #488AnonymousInactiveDoh! You even posted that in black and white and I missed it. Do I feel silly now >.<
I’ll go try that out now….
Marc
-
AuthorPosts
- You must be logged in to reply to this topic.