About Networking

Networking in Swingame allows you to write programs that can send messages to other programs.

Level

Expert

Details

It uses either the TCP or UDP protocol, and function in a similar manner within SwinGame.. The main steps of networking are:

  • Connect
  • Send Message
  • Disconnect.
Connection Data
The main datatype for networking is the Connection. This contains the sockets which messages are sent through, and the messages, as well as details about the destination such as the IP and Port. The connection data can be queries by using one of the many functions in the Networking library.

Connections are created by connecting to a Host, or when a client has connected to the Host. These Connections are added to a new connection queue and need to be fetched, removing them from the queue and returning them, so that you can assign them locally. Generally, the steps to connect involve :


  • Host Listens for connections
  • Client connects to host (returns a Connection)
  • Host accepts the connection (Adds the connection to the queue).
At this point, there should be a two way connection made.
Creating the host can be done by:
  • CreateTCPHost
  • CreateUDPHost
Connecting to the Host and returning a Connection Type can be done by:
  • CreateTCPConnection
  • CreateUDPConnection
Accepting the Connection and queueing a Connection can be done by:
  • AcceptTCPConnection
  • AcceptUDPConnection
Fetching the NewConnection can be done by:
  • FetchConnection
Sending a Message can be done by:
  • SendTCPMessage
  • SendUDPMessage
Receiving and queuing the message can be done by:
  • TCPMessageReceived
  • UDPMessageReceived
Read the Last or First Message Queued can be done by:
  • ReadMessage
  • ReadLastMessage
These functions form the bais of what will be used for networking by connecting and sending messages. You should choose the protocol based on your needs.
  • TCP: If the messages MUST be delivierd (Example. Chat Program).
  • UDP: If it is ok that some messages are not delivered (Example. A Game that sends coordinates, and only the latest is relevant).