0
使用J2ME我需要使用套接字通信將JPEG圖像發送到服務器。任何人都可以爲我的應用程序發送示例代碼嗎?圖像使用Socket通信發送到服務器
使用J2ME我需要使用套接字通信將JPEG圖像發送到服務器。任何人都可以爲我的應用程序發送示例代碼嗎?圖像使用Socket通信發送到服務器
查看Sun Developer Network的this article。它有一些簡約的例子,應該給你一些想法。
...
SocketConnection client = (SocketConnection) Connector.open("socket://" + hostname + ":" + port);
// set application-specific options on the socket. Call setSocketOption to set other options
client.setSocketOption(DELAY, 0);
client.setSocketOption(KEEPALIVE, 0);
InputStream is = client.openInputStream();
OutputStream os = client.openOutputStream();
// send something to server
os.write("some string".getBytes());
// read server response
int c = 0;
while((c = is.read()) != -1) {
// do something with the response
}
// close streams and connection
is.close();
os.close();
client.close();
...