Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SocialSocket.cs
Go to the documentation of this file.
3
5
6public class SocialSocket : ISocket
7{
8 private delegate void InternalReadCallback(byte[] data, int offset, int size, SocketReceiveCallback callback, object state);
9
11
12 public SocialSocket()
13 {
14 }
15
16 public SocialSocket(RemoteAddress remoteAddress)
17 {
18 _remoteAddress = remoteAddress;
19 }
20
22 {
23 if (_remoteAddress != null)
24 {
26 _remoteAddress = null;
27 }
28 }
29
31 {
32 return SocialAPI.Network.IsConnected(_remoteAddress);
33 }
34
36 {
37 _remoteAddress = address;
38 SocialAPI.Network.Connect(address);
39 }
40
41 void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
42 {
43 SocialAPI.Network.Send(_remoteAddress, data, size);
44 callback.BeginInvoke(state, null, null);
45 }
46
47 private void ReadCallback(byte[] data, int offset, int size, SocketReceiveCallback callback, object state)
48 {
49 int size2;
50 while ((size2 = SocialAPI.Network.Receive(_remoteAddress, data, offset, size)) == 0)
51 {
52 Thread.Sleep(1);
53 }
54 callback(state, size2);
55 }
56
57 void ISocket.AsyncReceive(byte[] data, int offset, int size, SocketReceiveCallback callback, object state)
58 {
59 new InternalReadCallback(ReadCallback).BeginInvoke(data, offset, size, callback, state, null, null);
60 }
61
63 {
64 }
65
67 {
68 return SocialAPI.Network.IsDataAvailable(_remoteAddress);
69 }
70
75
76 bool ISocket.StartListening(SocketConnectionAccepted callback)
77 {
78 return SocialAPI.Network.StartListening(callback);
79 }
80
82 {
83 SocialAPI.Network.StopListening();
84 }
85}
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
SocialSocket(RemoteAddress remoteAddress)
delegate void InternalReadCallback(byte[] data, int offset, int size, SocketReceiveCallback callback, object state)
void ReadCallback(byte[] data, int offset, int size, SocketReceiveCallback callback, object state)
static Terraria.Social.Base.NetSocialModule Network
Definition SocialAPI.cs:20
void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state=null)
void Connect(RemoteAddress address)
bool StartListening(SocketConnectionAccepted callback)
void AsyncReceive(byte[] data, int offset, int size, SocketReceiveCallback callback, object state=null)
RemoteAddress GetRemoteAddress()
delegate void SocketReceiveCallback(object state, int size)
delegate void SocketSendCallback(object state)