• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

SharpCraft TCP

Status
Not open for further replies.
Level 8
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:
attachment.php


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");
		}
	}
}
 

Attachments

  • ExampleMessages.jpg
    ExampleMessages.jpg
    182.3 KB · Views: 672
  • TCPPlugin.rar
    1.4 KB · Views: 84

Deleted member 219079

D

Deleted member 219079

How can someone join the server?
 
Level 6
Joined
Jul 30, 2013
Messages
282
any chance there will be an implementation that would allow say 1 player with the mod and 10 players with the vanilla client to be in the same game..?

this looks very juicy...
but excluding all vanilla players is way too expensive for a real mapper imo.
 
Status
Not open for further replies.
Top