- Joined
- Jul 24, 2006
- Messages
- 157
Hi,
here is a TCP Plugin I am working at the moment.
Uses SharpCraft 1.2.4.0.
Every message send is escaped with a new line character.
Example:
New Natives
Wurst Client Code
Java Server:
here is a TCP Plugin I am working at the moment.
Uses SharpCraft 1.2.4.0.
Every message send is escaped with a new line character.
Example:
New Natives
JASS:
//TCP
public native TCPConnectionCreate(string ip, int port) returns integer
public native TCPConnectionIsConnected(int id) returns boolean
public native TCPConnectionSend(int id, string message)
public native TCPConnectionHasMessage(int id) returns boolean
public native TCPConnectionReadMessage(int id) returns string
public native TCPConnectionClose(int id)
Wurst Client Code
JASS:
int connection
//Send messages entered as chat message
function sendMessage()
TCPConnectionSend(connection,GetEventPlayerChatString())
//Print messages recieved from the server
function recieveMessage()
while(TCPConnectionHasMessage(connection))
print(TCPConnectionReadMessage(connection))
init
//Create Connection
connection = TCPConnectionCreate("127.0.0.1", 5000)
//If Connection was succesfull
if(TCPConnectionIsConnected(connection))
print("Connection to Server succesfull!")
CreateTrigger()
..registerTimerEvent(0.1,true)
..addAction(function recieveMessage)
CreateTrigger()
..registerPlayerChatEvent(Player(0), "", false)
..addAction(function sendMessage)
else
print("Connection to Server failed!")
Java Server:
JASS:
public class Server {
private static int portNumber=5000;
public static void main(String args[]) {
try{
ServerSocket serverSocket = new ServerSocket(portNumber);
System.out.println("Started Server");
Socket clientSocket = serverSocket.accept();
System.out.println("Connected");
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(),"UTF-8"));
OutputStreamWriter writer = new OutputStreamWriter(clientSocket.getOutputStream(),"UTF-8");
PrintWriter out =new PrintWriter(writer, true);
out.println("Hello Client!");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Received: " + inputLine);
out.println("Server received: " + inputLine);
}
}catch(Exception e){
System.out.println("Connection Closed");
}
}
}