Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e1eaf84

Browse files
committed
readme format update
1 parent 57acfe3 commit e1eaf84

File tree

1 file changed

+65
-45
lines changed

1 file changed

+65
-45
lines changed

README.md

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,73 +21,93 @@
2121

2222
The easiest way to connect to your Socket.IO / node.js server is
2323

24-
SocketIO *socketIO = [[SocketIO alloc] initWithDelegate:self];
25-
[socketIO connectToHost:@"localhost" onPort:3000];
24+
``` objective-c
25+
SocketIO *socketIO = [[SocketIO alloc] initWithDelegate:self];
26+
[socketIO connectToHost:@"localhost" onPort:3000];
27+
```
2628

2729
If required, additional parameters can be included in the handshake by adding an `NSDictionary` to the `withParams` option:
2830

29-
[socketIO connectToHost:@"localhost"
30-
onPort:3000
31-
withParams:[NSDictionary dictionaryWithObjectsAndKeys:@"1234", @"auth_token", nil]
32-
];
33-
31+
``` objective-c
32+
[socketIO connectToHost:@"localhost"
33+
onPort:3000
34+
withParams:[NSDictionary dictionaryWithObjectsAndKeys:@"1234", @"auth_token", nil]
35+
];
36+
```
37+
3438
A namespace can also be defined in the connection details:
3539

36-
[socketIO connectToHost:@"localhost" onPort:3000 withParams:nil withNamespace:@"/users"];
37-
40+
``` objective-c
41+
[socketIO connectToHost:@"localhost" onPort:3000 withParams:nil withNamespace:@"/users"];
42+
```
43+
3844
There are different methods to send data to the server
3945

40-
- (void) sendMessage:(NSString *)data;
41-
- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function;
42-
- (void) sendJSON:(NSDictionary *)data;
43-
- (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function;
44-
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data;
45-
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data andAcknowledge:(SocketIOCallback)function;
46-
46+
``` objective-c
47+
- (void) sendMessage:(NSString *)data;
48+
- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function;
49+
- (void) sendJSON:(NSDictionary *)data;
50+
- (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function;
51+
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data;
52+
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data andAcknowledge:(SocketIOCallback)function;
53+
```
54+
4755
So you could send a normal Message like this
4856

49-
[socketIO sendMessage:@"hello world"];
50-
57+
``` objective-c
58+
[socketIO sendMessage:@"hello world"];
59+
```
60+
5161
or an Event (including some data) like this
5262

53-
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
54-
[dict setObject:@"test1" forKey:@"key1"];
55-
[dict setObject:@"test2" forKey:@"key2"];
56-
57-
[socketIO sendEvent:@"welcome" withData:dict];
63+
``` objective-c
64+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
65+
[dict setObject:@"test1" forKey:@"key1"];
66+
[dict setObject:@"test2" forKey:@"key2"];
5867

68+
[socketIO sendEvent:@"welcome" withData:dict];
69+
```
70+
5971
If you want the server to acknowledge your Message/Event you would also pass a SocketIOCallback block
6072

61-
SocketIOCallback cb = ^(id argsData) {
62-
NSDictionary *response = argsData;
63-
// do something with response
64-
};
65-
[socketIO sendEvent:@"welcomeAck" withData:dict andAcknowledge:cb];
66-
73+
``` objective-c
74+
SocketIOCallback cb = ^(id argsData) {
75+
NSDictionary *response = argsData;
76+
// do something with response
77+
};
78+
[socketIO sendEvent:@"welcomeAck" withData:dict andAcknowledge:cb];
79+
```
80+
6781
All delegate methods are optional - you could implement the following
6882

69-
- (void) socketIODidConnect:(SocketIO *)socket;
70-
- (void) socketIODidDisconnect:(SocketIO *)socket; // deprecated
71-
- (void) socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error;
72-
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet;
73-
- (void) socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet;
74-
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet;
75-
- (void) socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet;
76-
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error;
77-
83+
``` objective-c
84+
- (void) socketIODidConnect:(SocketIO *)socket;
85+
- (void) socketIODidDisconnect:(SocketIO *)socket; // deprecated
86+
- (void) socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error;
87+
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet;
88+
- (void) socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet;
89+
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet;
90+
- (void) socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet;
91+
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error;
92+
```
93+
7894
These two callbacks are deprecated - please don't use them anymore - they will
7995
be removed in upcoming releases:
8096

81-
- (void) socketIOHandshakeFailed:(SocketIO *)socket;
82-
- (void) socketIO:(SocketIO *)socket failedToConnectWithError:(NSError *)error;
97+
``` objective-c
98+
- (void) socketIOHandshakeFailed:(SocketIO *)socket;
99+
- (void) socketIO:(SocketIO *)socket failedToConnectWithError:(NSError *)error;
100+
```
83101

84102
To process an incoming Message just
85103

86-
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet
87-
{
88-
NSLog(@"didReceiveMessage() >>> data: %@", packet.data);
89-
}
90-
104+
``` objective-c
105+
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet
106+
{
107+
NSLog(@"didReceiveMessage() >>> data: %@", packet.data);
108+
}
109+
```
110+
91111
## Authors
92112

93113
Initial project by Philipp Kyeck <http://beta-interactive.de>.

0 commit comments

Comments
 (0)