public void Connect(TcpClient socket) { this.socket = socket; socket.ReceiveBufferSize = dataBufferSize; stream = socket.GetStream(); recievedData = new Packet(); recieveBuffer = new byte[dataBufferSize]; stream.BeginRead(recieveBuffer, 0, dataBufferSize, ReceiveCallBack, null); ServerSend.Welcome(id, "Welcome to the server"); }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = BufferSize; socket.SendBufferSize = BufferSize; stream = socket.GetStream(); receiveBuffer = new byte[BufferSize]; stream.BeginRead(receiveBuffer, 0, BufferSize, ReceiveCallback, null); ServerSend.Welcome(id, $"Welcome {id} !"); }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, "Hello is this thing on?"); }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); recievedData = new Packet(); buffer = new byte[dataBufferSize]; stream.BeginRead(buffer, 0, dataBufferSize, new AsyncCallback(RecieveCallback), null); ServerSend.Welcome(id); }
public void Connect(TcpClient client) { socket = client; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; networkStream = socket.GetStream(); receiveBuffer = new byte[dataBufferSize]; receivedPacket = new Packet(); networkStream.BeginRead(receiveBuffer, 0, dataBufferSize, new AsyncCallback(ReceiveCallback), null); // TODO: send welcome message to client! (done) ServerSend.Welcome(id, "Welcome to server!"); }
private void Connect() { ServerSend.Welcome(id, "Welcome to the server!"); }
/// <summary>Receives incoming UDP data.</summary> public static void UDPReceiveCallback(IAsyncResult _result) { try { IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, 0); byte[] data = udpListener.EndReceive(_result, ref clientEndPoint); udpListener.BeginReceive(UDPReceiveCallback, null); if (data.Length < 4) { return; } //Handle received Data using (Packet _packet = new Packet(data)) { int clientId = _packet.ReadInt(); //// If this is a new connection if (clientId == 0) { for (int i = 1; i < users.Count; i++) { if (users[i].udp.endPoint == null) { users[i].udp.Connect(clientEndPoint); users[i].name = _packet.ReadString(); clientId = i; break; } } //using (Packet _pack = new Packet((int)ServerPackets.welcome)) //{ // //you have to catch these info at client on the same order // _pack.Write(clientId); // _pack.Write("Welcome"); // _pack.WriteLength(); // UDPServer.SendUDPData(clientEndPoint, _pack); //} //sent to own client a Welcome message ServerSend.Welcome(clientId); return; } if (users[clientId].udp.endPoint.ToString() == clientEndPoint.ToString()) { users[clientId].udp.HandleData(_packet); } } } catch (Exception ex) { Console.WriteLine($"Error receiving UDP data: {ex}"); } }