Jump to content

Recommended Posts

Posted

I have an issue where sending strings with the PacketHandler inserts some wierd null chars and doesnt send along some chars.

I'm currently using this code to send strings:

            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
	DataOutputStream dataStream = new DataOutputStream(byteStream);

	try{
		dataStream.writeChars(str + "\n");
		PacketDispatcher.sendPacketToServer(PacketDispatcher.getPacket(ModInfo.CHANNEL, byteStream.toByteArray()));
	}catch(IOException ex){
			System.err.append("Faild to send String");
	}

 

and this to recieve:

 

String str = reader.readLine();

 

What am I doing wrong, or whats the proper way of sending strings?

 

 

Posted

for me,that works better.


       //reciving string
    	int n=data.readInt();
    	for (int i=0;i<n;i++) 
    		name=name+data.readChar();

       //sending string

    	out.writeInt(name.length());
    	int n = name.length();
    	for (int i=0;i<n;i++) 
    		out.writeChar(name.charAt(i));

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.