Hi guys,
I am new to Objective-C, I was wondering if you guys can give me some examples or tutorials on how to connect to server. I am traditional OO (Java, .NET) coder.
This is the way I connect to my server using Java. I am looking for something similar to this.
I am new to Objective-C, I was wondering if you guys can give me some examples or tutorials on how to connect to server. I am traditional OO (Java, .NET) coder.
This is the way I connect to my server using Java. I am looking for something similar to this.
Code:
HttpConnection connection = (HttpConnection) javax.microedition.io.Connector.open(serviceURL, Connector.READ_WRITE, true);
connection.setRequestProperty("User-Agent", userAgent);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestMethod(HttpConnection.POST);
DataOutputStream outputStream = connection.openDataOutputStream();
outputStream.writeByte(requestType);
outputStream.writeUTF(value);
int responseCode = connection.getResponseCode();
if (responseCode == HttpConnection.HTTP_OK || responseCode == HttpConnection.HTTP_CREATED) {
DataInputStream iStream = connection.openDataInputStream();
int returnCode = iStream.readByte();
} else if (responseCode == HttpConnection.HTTP_GATEWAY_TIMEOUT) {
throw new SessionException("Invalid session");
} else if (responseCode == HttpConnection.HTTP_INTERNAL_ERROR) {
throw new ApplicationException(-1, "Application error. Please contact support");
}
byte method = inputStream.readByte();
String name = inputStream.readUTF();
int count = inputStream.readInt();
boolean status = inputStream.readBoolean();
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException ioe) {}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ioe) {}
}
if (connection != null) {
try {
connection.close();
} catch (IOException ioe) {}
}