⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftserver.java

📁 java程序
💻 JAVA
字号:
import javax.microedition.io.*;
import java.io.*;
import javax.bluetooth.*;
import javax.obex.*;
import com.atinav.bcc.*;

public class FTServer extends ServerRequestHandler{

     public FTServer() throws BluetoothStateException {
     	
  	BCC.setPortName("COM2");  //setting the port number
    	BCC.setBaudRate(57600);//setting the baud rate
    	BCC.setConnectable(true);//connectable mode
        BCC.setDiscoverable(DiscoveryAgent.GIAC);               
     }	
     public int onConnect(HeaderSet request, HeaderSet reply) {
     	System.out.println("A OBEX connection has recieved .... ");
     	return ResponseCodes.OBEX_HTTP_OK;
     }
     public int onGet(Operation op) {
     	try{
     		//The server has recived a GET request for client.
	     	System.out.println("Recived a GET request from client .....  ");
	     	HeaderSet hdr = op.getReceivedHeaders(); 
	     	
	     	System.out.println("Server has recived a request for the file  "+(hdr.getHeader(HeaderSet.NAME)).toString());
		InputConnection inpcon = (InputConnection)Connector.open("file://name="+(hdr.getHeader(HeaderSet.NAME)).toString()+";mode=r");
		InputStream in     =  inpcon.openInputStream(); 
		byte[] fileAsBytes     = new byte[97];
		in.read(fileAsBytes);
		System.out.println("File read fully into the port ....");
		for(int i =0; i<fileAsBytes.length; i++)
			System.out.print((char)fileAsBytes[i]);
		DataOutputStream out = op.openDataOutputStream();
		out.write(fileAsBytes, 0, fileAsBytes.length);
		System.out.println("\n"+"File written back to client .... ");
		op.close();
		in.close();	     	
	    }
	catch(IOException e)    {
		System.out.println(e.getMessage());
	}
	catch(ArrayIndexOutOfBoundsException e)    {
		System.out.println(e.getMessage());
	}
     	return ResponseCodes.OBEX_HTTP_OK;
     }
     public static void main(String args[]) throws IOException {
     	
     	FTServer server        	 = new FTServer();
     	LocalDevice  localDevice = LocalDevice.getLocalDevice();
   	SessionNotifier sn = (SessionNotifier)Connector.open("btgoep://localhost:1106;name=FTP");
   	System.out.println("Waiting for a client connection ..... ");
   	sn.acceptAndOpen(server);
 	System.out.println("A Client now connected .... ");

     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -