Currently I’m just playing around trying to create my own custom server using python. Right now I haven’t accomplished much but I’m having issues reading the data I send over.
I’m using just the sample code from | Unity Transport | 0.4.1-preview.1
with a slight modification to the NetworkEvent.Type.Connect if statement.
ORIGINAL
if (cmd == NetworkEvent.Type.Connect)
{
Debug.Log("We are now connected to the server");
uint value = 1;
var writer = m_Driver.BeginSend(m_Connection);
writer.WriteUInt(value);
m_Driver.EndSend(writer);
}
ALTERED
if (cmd == NetworkEvent.Type.Connect)
{
Debug.Log("We are now connected to the server");
uint value = 1;
var writer = m_Driver.BeginSend(m_Connection);
//
string message = "hello";
writer.WriteBytes(stringToNativeArray(message));
m_Driver.EndSend(writer);
}
When I send the hello message my python server receives this
b’\x00\x00\xee\xda’
I’m confused as to what this is. I have very limited knowledge of networking and the transport layer but any help would be appreciated. (from an actual answer to additional online resources to help accomplish this task)
The simple UDP Python server
import socket
import sys
import ctypes
import json
from ast import literal_eval
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', 9000)
sock.bind(server_address)
while True:
print('
waiting to receive message’)
data, address = sock.recvfrom(4096)
if data:
print(data)
sent = sock.sendto(bytes(ctypes.c_ulong(500)), address)
print('sent to ' + str(address))
Ignore the useless imports, I’ve been trying various things.