Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

J2ME - getIPdevice

// Retrevie IP device

package org.socketdemo;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class SocketDEMO extends MIDlet implements CommandListener
{
	protected SocketDEMO midlet = this;
	
	private Alert info;
	
	protected void destroyApp(boolean value) throws MIDletStateChangeException
	{
		notifyDestroyed();
	}

	protected void pauseApp()
	{

	}

	protected void startApp() throws MIDletStateChangeException
	{
		new Thread()
		{
			public void run()
			{
				SocketConnection socket = null;
				
				try
				{
					socket = (SocketConnection) Connector.open("socket://193.204.114.233:13");
					
					socket.openInputStream();
					
					info = new Alert("Info", "Current IP: " + socket.getLocalAddress() + "\nPort: " + socket.getLocalPort(), null, AlertType.INFO);
					info.setTimeout(Alert.FOREVER);
					info.setCommandListener(midlet);
					
					getDisplay().setCurrent(info);
				}
				catch(Exception error)
				{
					info = new Alert("Info", "Current IP: N/A\nPort: N/A", null, AlertType.INFO);
					info.setTimeout(Alert.FOREVER);
					info.setCommandListener(midlet);
					
					getDisplay().setCurrent(info);
				}
				finally
				{
					if(socket != null)
					{
						try
						{
							socket.close();
						}
						catch(Exception error)
						{
							
						}
					}
				}
			}
		}.start();
	}
	
	protected Display getDisplay()
	{
		return Display.getDisplay(this);
	}

	public void commandAction(Command cmd, Displayable dsp)
	{
		if(cmd == Alert.DISMISS_COMMAND)
		{
			try
			{
				destroyApp(true);
			}
			catch(MIDletStateChangeException error)
			{
			
			}
		}
	}
}

Python - SendSMS over BT and AT

// Send SMS over Bluetooth (AT Command)

import bluetooth

sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sockfd.connect(('00:00:00:00:00:00', 1)) # BT Address
sockfd.send('ATZ\r')
sockfd.send('AT+CMGF=1\r')
sockfd.send('AT+CSCA="+393359609600"\r') # Client TIM ITA
sockfd.send('AT+CMGS="+39xxxxxxxxxx"\r') # TO PhoneNumber
sockfd.send('Messaggio da mandare...\n')
sockfd.send(chr(26)) # CTRL+Z
sockfd.close()
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS