Sending packets over TCP socket
You should use Wireshark
With Wireshark you can sniff traffic from/to hosts. It makes it really easy to spot where your application does something else than the standard client.
BTW you have a \n in front of agent=, it might be the problem
Francis
Updated on June 04, 2022Comments
-
Francis almost 2 years
I'm writing this tiny utility method to test sending raw packets to a specific messaging network (planning on developing a client to connect to it).
The network is the Deviantart messaging network (chat.deviantart.com:3900; TCP).
My class:
protected void connect() throws IOException{ Socket dAmn = null; //BufferedWriter out = null; PrintWriter out = null; BufferedReader in = null; /* * Create Socket Connection */ try{ dAmn = new Socket("chat.deviantart.com", 3900); /*out = new BufferedWriter(new OutputStreamWriter(dAmn.getOutputStream()));*/ out = new PrintWriter(dAmn.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(dAmn.getInputStream())); } catch(SocketException e){ System.err.println("No host or port for given connection"); //handle } catch(IOException e){ System.err.println("I/O Error on host"); //handle } String userInput; BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in)); /* * dAmn communication */ while((userInput = userIn.readLine()) != null){ out.write(userInput); System.out.println(in.readLine()); } if(in!=null) in.close(); if(out!=null) out.close(); if(dAmn!=null) dAmn.close(); }
The server requires a handshake to be sent before the login may proceed. A typical login packet looks like thus:
dAmnclient damnClient (currently 0.3) agent= agent
Every packet must end with a newline and a null.
My handshake packet would look something like:
dAmnClient 0.3\nagent=SomeAgent\n\0
However the server simply replies with disconnect
I think something is incorrectly being parsed, any advice? Also, if you're super intersted in helping me out: here's some quick documentation on the client -> server dAmn protocol: http://botdom.com/wiki/DAmn#dAmnClient_.28handshake.29
-
Francis about 13 yearsDoes't .write() automatically flush?