Results 1 to 10 of 10
- 10-22-2012, 11:58 AM #1
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
(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...
- 10-22-2012, 05:45 PM #2
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)
- 10-22-2012, 09:06 PM #3
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
- 10-23-2012, 12:40 AM #4
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)
- 10-23-2012, 09:22 AM #5
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
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...
- 10-23-2012, 09:40 AM #6
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
- 10-23-2012, 09:51 AM #7
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
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...
- 10-23-2012, 10:15 AM #8
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)
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.
- 10-23-2012, 10:27 AM #9
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
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-23-2012, 10:50 AM #10
Member
- Join Date
- Jul 2012
- Location
- Earth
- Posts
- 75
- Rep Power
- 0
Re: (ExtremelyNeedHelp) Please help to Turn TCP server in to UDP (really short code)
Errr ... DatagramSocket !!!! Lesson: All About Datagrams (The Java™ Tutorials > Custom Networking)
Similar Threads
-
Cant find the problem with this short code.
By MarioBrawler in forum New To JavaReplies: 8Last Post: 05-26-2012, 12:59 AM -
why my car can not turn left and turn 5 round,Help!!THx
By seongchog in forum Java AppletsReplies: 7Last Post: 03-01-2012, 09:53 AM -
C server code - Java CLient Code _ TCP Connection Problem
By rmd22 in forum NetworkingReplies: 0Last Post: 02-21-2011, 11:50 AM -
short month = Short.parseShort(splitarray[2].toString()));
By AndyC in forum New To JavaReplies: 3Last Post: 02-20-2011, 12:15 PM -
[SOLVED] Turn off NetBeans code blocker
By xcallmejudasx in forum New To JavaReplies: 5Last Post: 05-04-2009, 05:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks