Log in

View Full Version : Need help opening a socket to send data to Classmate running putty.


Daniel
03-03-2011, 11:42
Attention coding wizards:

My goal is to send diagnostic text to the Classmate to be displayed using putty as a custom/flexible diagnostic display. Here is my code:


import javax.microedition.io.SocketConnection;
import javax.microedition.io.Connector;
import java.io.OutputStream;
import java.io.IOException;


private SocketConnection socket ; // Socket to Classmate
private OutputStream outputStream;


try {
socket = (SocketConnection) Connector.open("telnet://10.36.38.6:23");
socket.setSocketOption(SocketConnection.LINGER, 5);

outputStream = socket.openOutputStream();

System.out.println("Diagnostic socket open.\r\n");

outputStream.write("Goodbye World!\r\n".getBytes());

outputStream.close();

} catch (IOException e) {
System.out.println("Error opening diagnostic socket: " + e.getMessage() + "\r\n");
}


This code gets an error stating "Telnet protocol is not available" (or something similar).

I will try another socket number tonight.

But does anyone have any suggestions how to open a socket or stream to send that to the classmate.

Dan

Daniel
03-03-2011, 13:48
According to Team Update #5 there are 5 ports available: TCP 1180, UDP 1130, UDP 1140, HTTP 80 and HTTP 443.

FIRST must have disabled all other ports.

SuperBK
03-03-2011, 14:12
I don't think Putty can be set to listen on a port as a telnet server. Correct me if I'm wrong. Usually putty is used as a client to connect to a listening "server'. You may need to call 'listen' (specifying an availabe port) and 'accept' in your CRIO code and then Putty on the classmate can connect to it. Exaclty how to do that in java is beyond what I can look up right now.

spartango
03-03-2011, 19:14
I'll leave this here:
http://code.google.com/p/grtframework/source/browse/#svn%2Ftrunk%2FCurrentBot%2Fsrc%2Fcom%2Fgrt192%2Fn etworking

you should find examples for what you're looking for, as well as other networking setups. This code has been tested, so you should be good to go.

derekwhite
04-03-2011, 09:55
You need to use the "socket:" or "serversocket:" protocols instead of "telnet:" when you create your connection. And definitely check out spartango's example code.

Daniel
04-03-2011, 11:46
I tryied spartango's link, but got page not found.

Spartango, can you please paste the code into this thread or create an attachment?

derekwhite
04-03-2011, 15:04
You can find more information and example code on networking and file i/o in these articles:

http://developers.sun.com/mobility/midp/articles/genericframework/
http://developers.sun.com/mobility/midp/articles/midp2network/

Daniel
09-03-2011, 12:21
spartango and derek, I've tried to test this sample but can not find definitions for the SocketListener and SocketEvent objects.

Has this code every been tested/run in our FIRST configuration?

I would still like to get this working. As a interm fix I am getting a Serial RS232 to USB converter and will use putty listening to COM1.

derekwhite
10-03-2011, 08:41
Hi, those classes are also in spartango's code:

http://code.google.com/p/grtframework/source/browse/trunk/CurrentBot/src/com/grt192/networking/SocketListener.java
http://code.google.com/p/grtframework/source/browse/trunk/CurrentBot/src/com/grt192/networking/SocketEvent.java