Results 1 to 10 of 10
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Unhappy (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Hi, I've made a little mistake on making the server for my game, I've made a TCP instead of UDP...
    But UDP code is quite different and not sure how to start a thread class when client connects..
    So here is the code:

    Java Code:
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.ArrayList;
    public class Connector 
    {
    	public static ArrayList<Socket> ConnectionArray = new ArrayList<Socket>();
    	public static ArrayList<String> CurrentUsers = new ArrayList<String>();
    	public static int ConnectionTimeOut = 5000;
    	public static PrintWriter OUT;
    	public static void main(String[] args) throws IOException
    	{
    		try
    		{
    			
    			final int PORT = 2807;
    			ServerSocket SERVER = new ServerSocket(PORT);
    			System.out.println("Server launched.");
    			while(true)
    			{
    				Socket SOCK = SERVER.accept();
    				ConnectionArray.add(SOCK);
    				OUT =  new PrintWriter(SOCK.getOutputStream());
    				OUT.println("Connected to the server. \n");
    				OUT.flush();
    				System.out.println("Someone connected.");
    				
    				ChatServer CHAT = new ChatServer(SOCK);
    				Thread X = new Thread(CHAT);
    				X.start();
    			}
    		}
    		catch(Exception X) {System.out.print(X);}
    	}
    }
    WARNING I am Russian so it's possible that I wont understand you correctly...

  2. #2
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)


  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Quote Originally Posted by sabre150 View Post
    Cross posted
    What do you mean?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  4. #4
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Quote Originally Posted by Lionlev View Post
    What do you mean?
    When posting a topic to multiple forums one should indicate which other forums one has posted to so that readers will not waste time answering a query that has been answered in another forum.

  5. #5
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Ehhh, that is the first time I posted that...
    WARNING I am Russian so it's possible that I wont understand you correctly...

  6. #6
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Quote Originally Posted by Lionlev View Post
    Ehhh, that is the first time I posted that...
    Sorry. Please ignore me ! I thought I had seen the same post on another forum but, since I can't find it any more and the link I posted came back here, it seems I was mistaken.

  7. #7
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    lol it's ok
    Good luck! By the way, you got any experience on "Datapackets" in java?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  8. #8
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Quote Originally Posted by Lionlev View Post
    lol it's ok
    Good luck! By the way, you got any experience on "Datapackets" in java?
    I use TCP rather than UDP so probably can't help. There are many books on Java network programming that you can download; just Google for "Java UDP network programming". OK, you probably won't get the code handed to you on a plate but you will learn much more by researching and coding it yourself.

  9. #9
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Yeah but just a problem is that I've made a rpg side scroller and the TCP server and it works, I can see the clients, clients can see my char but when everyone are walking so much slower than the usual speed because clients getting each movement and the client even didn't process some yet, the coordinates are still collecting there and collecting.. Probably UPD client will get only the latest coordinates but lol the problem is that I have no idea how to start a new thread from it
    Like Socket SOCK = server.accept(); so I can use the SOCK to start the thread, I can't seem to find something like Socket in the Datapacket..
    WARNING I am Russian so it's possible that I wont understand you correctly...

  10. #10
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)

    Quote Originally Posted by Lionlev View Post
    , I can't seem to find something like Socket in the Datapacket..
    Errr ... DatagramSocket !!!! Lesson: All About Datagrams (The Java™ Tutorials > Custom Networking)

Similar Threads

  1. Cant find the problem with this short code.
    By MarioBrawler in forum New To Java
    Replies: 8
    Last Post: 05-26-2012, 01:59 AM
  2. why my car can not turn left and turn 5 round,Help!!THx
    By seongchog in forum Java Applets
    Replies: 7
    Last Post: 03-01-2012, 10:53 AM
  3. Replies: 0
    Last Post: 02-21-2011, 12:50 PM
  4. Replies: 3
    Last Post: 02-20-2011, 01:15 PM
  5. [SOLVED] Turn off NetBeans code blocker
    By xcallmejudasx in forum New To Java
    Replies: 5
    Last Post: 05-04-2009, 06:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •