Sending packets over TCP socket?

Up vote 1 down vote favorite share g+ share fb share tw.

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 java parsing sockets networking messaging link|improve this question asked Mar 12 '11 at 22:54Francis62.

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.

The line read from the user will not contain the actual line termination, and it will not contain any null-termination either. Typing \n at the input will actually transmit "\n" rather than a new-line. You could add a new-line by replacing write with println (careful, it may use \n, \r\n or just \r depending on platform): out.

Println(userInput); You could support packet termination e.g. By checking for a specific user input, like so: if (userInput. Equals(". ")) { out.

Write((char) 0); out.flush(); } else { out. Println(userInput); } The user can now terminate packets by typing a dot. (Actually the code could perform the handshake automatically without waiting for user input, but that's another story.

).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions