My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
SocketWrapper  
How to use the socket wrapper
Featured, Phase-Implementation
Updated Feb 4, 2010 by clevera...@mac.com

The class LXSocket is a convenient wrapper for low-level sockets which allows for sending atomic values and objects over the network. ObjC objects are serialized.

A server socket can be created as follows:

	LXSocket* serverSocket = [[LXSocket alloc] init];
	[serverSocket bindToPort: port];
	[serverSocket listen: maxNumberOfConnections];

One can then accept connections using the accept method:

	LXSocket* socket = [serverSocket accept];

To create a client socket, use:

	LXSocket* socket = [[LXSocket alloc] init];
	if ([socket connect: host port: port] == NO) { [socket release]; NSLog(@"cannot create socket"); }

If the socket has been created successfully, you can send and receive atomic values and objects:

	id object = [socket readObject];
	[socket sendObject: object];

Sent/received objects must conform to NSCoding, i.e., they have to respond to encodeWithCoder: and initWithCoder:.

Comment by thomas.c...@gmail.com, Jul 21, 2009

Without your beautiful class I would have some difficulties to finish my project properly! So thank you very much:) I don't like to program when it's too close to C, I prefer using abstraction. You saved me!

Comment by thomas.c...@gmail.com, Jul 21, 2009

Aaah and I want to add something, you class is also useful to make a cocoa application communicate with a cocoa touch application (that also helped me :))

Comment by diego.ag...@gmail.com, Oct 2, 2010

Hey im having som issues with this class, maybe i haven't tried everything but im not sure what is wrong. I have a java server and an iphone app that im using for tests and after both sockets are connected i do an out.printLn("Hello"); (its a PrintWriter? btw), in the iphone app i do readString? and there is the problem the app just stops working..

i would appreciate some help if anyone has tried doing this before

thanks in advance.

Comment by owenge...@gmail.com, Aug 29, 2011

i was hoping for some direction since my other venues (stackoverflow and apple dev forums) cannot figure this out. basically i have a server and client sending the same data. const char connectByteArray1 = {

0x01, 0x00, 0x07, 0x7f, 0x00, 0x00, 0x01, 0x00, 0x03, 0x40
}; sendBytes:bytes length:len?;
but i cannot figure out how to read the message with readbytes or readobject

Comment by owenge...@gmail.com, Aug 29, 2011

i am getting results now but only up to 8bytes. and the hex string im trying to get back is 10bytes.

Comment by owenge...@gmail.com, Aug 30, 2011

figured it out, thanks anyways

Comment by luigipar...@gmail.com, Oct 25, 2011

Hi! I have to transfer information from a client (iPhone) to a server (Windows PC). The server is written in VB6 (using Winsock), iPhone LXSocket use. The server receives the data, however, in the head and tail are characters in my message were not there initially. Unfortunately, when the server responds (String) LXSocket waits and does not recognize. You know give me a solution? They are incompatible? Thank you, Luigi.

Comment by Ayhan.Ug...@gmail.com, Jan 10, 2012

hi, luigi... can you share your project?

Comment by neeraj.k...@halosys.com, Feb 21, 2012

zxs


Sign in to add a comment
Powered by Google Project Hosting