Jump to content
  • Advertisement

Xolitude

Member
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

118 Neutral

About Xolitude

  • Rank
    Member
  1. Update: I fixed it. All I had to do was add a check to see if the client is connected like so: private void readExistingClient() throws Exception { // Read from connected clients. for (GameClient c : connectedPlayers) { while (c.PlayerSocket.isConnected()) { // This line here. DataInputStream clientPacket = new DataInputStream(c.PlayerSocket.getInputStream()); readPacket(c.PlayerSocket, clientPacket); } } }
  2. I tried removing the "return" because it looked weird to me too, but it still does the same thing it was doing.
  3. Hey guys!   So, My client and server are both in Java. The server is only receiving one player movement packet from the client and then can't receive any other packets.   Code: Server reading a movement packet: case Movement: float receivedX = packetStr.readFloat(); float receivedY = packetStr.readFloat(); for (GameClient s : connectedPlayers) { if (s.PlayerSocket.equals(client)) { s.X += receivedX; s.Y += receivedY; System.out.println("X:"+s.X + " - Y:"+s.Y); return; } } break; Client sending position every frame update: public void tick() { try { BasePacket movePacket = (BasePacket) new Packet3Movement(this.velX, this.velY); PacketWriter w = new PacketWriter(server, movePacket); w.sendPacket(); } catch (Exception e) { e.printStackTrace(); } } The server is only printing the position once and then not printing it at all. When I try sending a disconnect packet, the server doesn't receive that after receiving the movement packet. Any help?
  4. Hm, I'm thinking about just re-writing the server into Java... I didn't really get far on the C# one because of this packet issue. I can't seem to get this to work right
  5. Is there anyway of sending a little-endian bytebuffer through a dataoutputstream to the server?
  6. Hm, I'll look into it and I'll report back here :) thanks for this heads up.
  7.   The server prints out a much bring length then the client does when testing...
  8. Can you show us all of your code between the point where you read the packetId and print it out to the console? Your original post doesn't contain anything that will try to print the packetId to the console.   Server: public class PacketReader : BinaryReader { public PacketReader(NetworkStream str) : base(str) { } public void s() { int le = ReadInt32(); Console.WriteLine(le); // Prints a big int. string m = Encoding.ASCII.GetString(ReadBytes(le)); // Doesn't print anything out but causes an exception when i close the client. Console.WriteLine(m); } } Client: public void sendPacket() { try { dos = new DataOutputStream(server.getOutputStream()); dos.writeInt(packet.getPacketID().length()); dos.writeBytes(packet.getPacketID()); dos.flush(); } catch (IOException e) { e.printStackTrace(); } } These two show how the bytes are sent, and how the server tries to read them.   And... Server: public void handleConnection() { NetworkStream playerStream = client.GetStream(); int recv; byte[] data = new byte[1024]; Console.WriteLine("Player has connected: {0}", client.Client.RemoteEndPoint); if (client.Client.Available > 0) { PacketReader s = new PacketReader(playerStream); s.s(); } } This is currently how it checks if the data is available and uses "s.s" to print it out.
  9. The server still prints out a blank string even I use it exactly how you did...
  10. Hey guys! I am writing a multiplayer game and I'm going on to the networking now. But I run into an issue. My C# server is not reading the bytes sent from my java client correctly.   This is the code on both sides: Client: public void sendPacket() { try { dos = new DataOutputStream(server.getOutputStream()); dos.writeBytes(packet.getPacketID()); dos.flush(); } catch (IOException e) { e.printStackTrace(); } } Server: NetworkStream playerStream = client.GetStream(); int recv; byte[] data = new byte[client.ReceiveBufferSize]; Console.WriteLine("Player has connected: {0}", client.Client.RemoteEndPoint); if (client.Client.Available > 0) { PacketReader s = new PacketReader(data); s.s(); // This does "ReadString()" from BinaryReader. } My Strings show up blank in the console. Any help?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!