You Are Here:

Community: Developer Discussion Boards

#1 Old isNotVNC (but I need help!) - 2008-10-27, 19:39

Join Date: Oct 2008
Posts: 5
rotra
Offline
Registered User
I was looking for a VNC server for Symbian 3rd. I've found one but commercial and with some key issue on my Nokia E51. It doesn't matter... I do something myself, what's the problem?!

Ok, I've looked for framebuffer and other technical stuff. Sorry, I've not enought time to investigate that.

So... I've taken a different approach. is Not VNC, but do some thing similar (and it's ok for my needs): a pys60 client and a java server on PC.

For the server:
download from somewhere a bluetooth driver that support RFCOMM for your device. I'm using Blue Cove on Mac OS X.

Run the server FIRST, than the client.

For the client:
I've used the keypress module by cyke64 (http://cyke64.googlepages.com/). So install PythonShell unsigned and keypress unisgned (but both signed by yourself). Than run the script below.

Usage: look the client.py code for knowing commands you can put in the textarea. The screen refresh after any CR.

Before the code, I explain my problems:

1) I'm not a mobile programming guru, nor a java bluetooth programming professional, so the code is "Just che funz" (meaning, "Hope it runs")

2) There is not auto refresh of the video. Hit "GET" button to refresh or type something in the textarea. All of that after connecting.

3) OK, SOME PROBLEMS I'M NOT ABLE TO SOLVE SO **PLEASE** SOMEBODY HELP ME!!!
3a) If the phone goes in save screen I've found NO WAY to get focus back to the system!
3b) Editing a message, no way to get letters, only numbers. I guess this is a very dummy problem... but... I'm..... :-(
Reply With Quote

#2 Old (continued) - 2008-10-27, 19:40

Join Date: Oct 2008
Posts: 5
rotra
Offline
Registered User
OK, java part (but no way to upload a zip file):

-------------------------------
Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.bluetooth.*;
import javax.microedition.io.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.*;
/**
 * Class that implements an SPP Server which accepts single line of
 * message from an SPP client and sends a single line of response to the client.
 */
@SuppressWarnings("unused")
public class IsNotVNC extends JFrame {

	private static final long serialVersionUID = 913025249206080080L;
	private JLabel label = new JLabel();
	private PrintWriter pWriter=null;
    private byte[] bbuf=new byte[128000];
    private InputStream inStream=null;

	//start server
	private void startServer() throws IOException{
		startPanel();

		//Create a UUID for SPP
		UUID uuid = new UUID("1101", true);
		//Create the servicve url
		String connectionString = "btspp://localhost:" + uuid +";name=isNotVNC";
		//open server url
		StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
		//Wait for client connection
		System.out.println("\nServer Started. Waiting for clients to connect...");
		boolean exit=false;
		while(!exit) {
			StreamConnection connection=streamConnNotifier.acceptAndOpen();
			RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
			System.out.println("Remote device address: "+dev.getBluetoothAddress());
			//System.out.println("Remote device name: "+dev.getFriendlyName(true));
			//read string from spp client
			inStream=connection.openInputStream();
			String lineRead="";
			OutputStream outStream=connection.openOutputStream();
			pWriter=new PrintWriter(new OutputStreamWriter(outStream));

			pWriter.println("Start");
			pWriter.write("Begin String from isNotVNC\n");
			pWriter.flush();
	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	        sendGet();
			while(lineRead==null || !lineRead.equals("QUIT")) {
				if(inStream.available()>0) {
					int l=inStream.read(bbuf);
					System.out.println(new String(bbuf,0,l));
				}
				lineRead=in.readLine();
				if(lineRead!=null) {
					pWriter.println(lineRead);
					pWriter.flush();
					sendGet();
				}
			}
			exit=true;
			pWriter.flush();
			pWriter.close();
			streamConnNotifier.close();
		}
	}
	
	protected void sendGet() {
		pWriter.println("GET");
        pWriter.flush();
        try {
			getGet();
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
	
	protected void sendText(String text) {
		pWriter.println(text);
        pWriter.flush();
        sendGet();
	}
	
	protected void getGet() throws IOException {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		while(inStream.available()==0);
		int l=inStream.read(bbuf);
		//save(bbuf,l);
		display(bbuf);		
	}

	@SuppressWarnings("unused")
	private void save(byte[] bbuf, int l) {
		try {
			File f=new File("/image.jpg");
			FileOutputStream fo=new FileOutputStream(f);
			fo.write(bbuf, 0, l);
			fo.flush();
			fo.close();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

	private void display(byte[] cbuf) {
		ImageIcon icon = new ImageIcon(cbuf);
		label.setIcon(icon);			
	}
	public static void main(String[] args) throws IOException {
		//display local device address and name
		LocalDevice localDevice = LocalDevice.getLocalDevice();
		System.out.println("Address: "+localDevice.getBluetoothAddress());
		System.out.println("Name: "+localDevice.getFriendlyName());
		IsNotVNC isNotVNC=new IsNotVNC();
		isNotVNC.startServer();
	}

	private void startPanel() {
		setSize(500,500);
		JPanel panel = new JPanel();
		panel.setBackground(Color.CYAN);
		
		/*
		 * ImageIcon icon = new ImageIcon(cbuf);
		 * label.setIcon(icon);
		 */
		panel.add(label);
		
		JButton button = new JButton("GET");

	    ActionListener actionListener = new ActionListener() {
	      public void actionPerformed(ActionEvent actionEvent) {
	    	sendGet();
	      }
	    };
		
	    button.addActionListener(actionListener);
	    panel.add(button);
	    
	    final JTextArea textArea = new JTextArea( "", 10, 10 );
	    
	    KeyListener keyListener = new KeyListener() {
		      

			public void keyPressed(KeyEvent ke) {
				// TODO Auto-generated method stub
				
			}

			public void keyReleased(KeyEvent ke) {
				// TODO Auto-generated method stub
				
			}

			public void keyTyped(KeyEvent ke) {
				char c=ke.getKeyChar();
				if(c=='\n') {
					String s=textArea.getText();
					textArea.setText("");
					sendText(s);
				}
				
			}
		};
	    
	    textArea.addKeyListener(keyListener);
	    
	    
	    panel.add(textArea);
		this.getContentPane().add(panel);

		setVisible(true);
		
	}
}
-----------------------------------------------------------

And client python (ooh, beaware of indentation :-( ):

-----------------------------------------------------------
Code:
import socket
import appuifw
import e32
import graphics
#from key_modifiers import * 
from key_codes import * 
import keypress

class BTReader:
    def connect(self):
        self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
        addr,services=socket.bt_discover()
        print "Discovered: %s, %s"%(addr,services)
        if len(services)>0:
            import appuifw
            choices=services.keys()
            choices.sort()
            choice=appuifw.popup_menu([unicode(services[x])+": "+x
                                       for x in choices],u'Choose port:')
            port=services[choices[choice]]
        else:
            port=services[services.keys()[0]]
        address=(addr,port)
        print "Connecting to "+str(address)+"...",
        self.sock.connect(address)
        print "OK." 
    def read(self):
        return self.sock.recv(1024)
    def close(self):
        self.sock.close()
    def send(self,data):
    	self.sock.send(data)
	

imagename="e:\Images\snap.jpg"
bt=BTReader()
bt.connect()
bt.send("ciao\n")
esegui=True
while(esegui):
	try:
		received=bt.read()
		print "Received: "+received
		if received.startswith('QUIT'):
			print "Quitting"
			esegui=False
		if received.startswith('GET'):
			graphics.screenshot().save( imagename )
			fh = file(imagename, 'rb');
			bt.send(fh.read())
			fh.close()
			print "SENT SCREENSHOT!"
		if received.startswith('LSoft'):
			keypress.simulate_key(EKeyLeftSoftkey,EKeyLeftSoftkey)
		if received.startswith('RSoft'):
			keypress.simulate_key(EKeyRightSoftkey,EKeyRightSoftkey)
		if received.startswith('Left'):
			keypress.simulate_key_mod(EKeyLeftArrow, EKeyLeftArrow,EModifierKeypad)
		if received.startswith('Right'):
			keypress.simulate_key_mod(EKeyRightArrow, EKeyRightArrow,EModifierKeypad)
		if received.startswith('Up'):
			keypress.simulate_key_mod(EKeyUpArrow, EKeyUpArrow,EModifierKeypad)
		if received.startswith('Down'):
			keypress.simulate_key_mod(EKeyDownArrow, EKeyDownArrow,EModifierKeypad)
		if received.startswith('0'):
			keypress.simulate_key(EKey0,EKey0)
		if received.startswith('1'):
			keypress.simulate_key(EKey1,EKey1)
		if received.startswith('2'):
			keypress.simulate_key(EKey2,EKey2)
		if received.startswith('3'):
			keypress.simulate_key(EKey3,EKey3)
		if received.startswith('4'):
			keypress.simulate_key(EKey4,EKey4)
		if received.startswith('5'):
			keypress.simulate_key(EKey5,EKey5)
		if received.startswith('6'):
			keypress.simulate_key(EKey6,EKey6)
		if received.startswith('7'):
			keypress.simulate_key(EKey7,EKey7)
		if received.startswith('8'):
			keypress.simulate_key(EKey8,EKey8)
		if received.startswith('9'):
			keypress.simulate_key(EKey9,EKey9)
		if received.startswith('*'):
			keypress.simulate_key(EKeyStar,EKeyStar)
		if received.startswith('#'):
			keypress.simulate_key(EKeyHash,EKeyHash)
		if received.startswith('Backspace'):
			keypress.simulate_key(EKeyBackspace,EKeyBackspace)
		if received.startswith('Del'):
			keypress.simulate_key(EKeyBackspace,EKeyBackspace)
		if received.startswith('Yes'):
			keypress.simulate_key(EKeyYes,EKeyYes)
		if received.startswith('No'):
			keypress.simulate_key(EKeyNo,EKeyNo)
		if received.startswith('Menu'):
			keypress.simulate_key(EKeyMenu,EKeyMenu)
		if received.startswith('Select'):
			keypress.simulate_key(EKeySelect,EKeySelect)
		if received.startswith('Edit'):			keypress.simulate_key(EKeyEdit,EKeyEdit)			
	except:
		pass
bt.close()
print "QUITTED"
---------------------------------------------------------------


That's all folk... I think I'll have not too much time to go on with this "project". So I make the code public, assume a GNU/GPL Licence on it.
Anybody who wants to go on and/or try to resolve the keyboard issues are welcome.

Bye (and thank's),

rotra
Last edited by rotra : 2008-10-30 at 11:28. Reason: indentation
Reply With Quote

#3 Old Re: isNotVNC (but I need help!) - 2008-10-28, 08:46

Join Date: Sep 2007
Posts: 395
Location: Bhavnagar
Send a message via Yahoo to james1980
james1980's Avatar
james1980
Offline
Forum Nokia Champion
Hi,
It is good idea to make your code public so that any body can work on it, but one advice please use the code tag given as a '#' sign it would maintain all space and indentation.
Bye.


Jajal Mehul
Reply With Quote

#4 Old Re: isNotVNC (but I need help!) - 2008-10-30, 11:29

Join Date: Oct 2008
Posts: 5
rotra
Offline
Registered User
OK, Thank's . It's looks better now!
Reply With Quote

#5 Old Re: isNotVNC (but I need help!) - 2008-10-30, 12:59

Join Date: Oct 2008
Posts: 5
rotra
Offline
Registered User
I've found

http://discussion.forum.nokia.com/fo...=139220&page=3

need to merge the two things...
Reply With Quote

#6 Old Re: isNotVNC (but I need help!) - 2008-11-02, 11:15

Join Date: Oct 2008
Posts: 5
rotra
Offline
Registered User
I've uploaded all on http://code.google.com/p/isnotvnc/. It runs for me, it makes the job... someway.

r.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia