|
SocketWrapper
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:. |
► Sign in to add a comment
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!
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 :))
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.
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 = {
but i cannot figure out how to read the message with readbytes or readobjecti am getting results now but only up to 8bytes. and the hex string im trying to get back is 10bytes.
figured it out, thanks anyways
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.
hi, luigi... can you share your project?
zxs