Sockets question (multiple user, client-server application)

I'm new to sockets and I think I've been designing my application all wrong.
I've been using the KKMultiServer example from this website. It creates new threads using the Socket.accept() function. However, all the clients connect to the same port on the server.
What I'm creating is a multi-user TicTacToe program. So far it's only for two players, but I would like to create a game "lobby" where lots of users can connect and play games with each other.
Do I need to specifcy local ports for the clients that are connecting? Should I be using different ports on the server for each user so the traffic doesn't get mixed up?

a socket is made up of 4 elements.
1) the server or host IP address
2) the server port
3) the client IP address
4) the client port
for a socket to be unqiue one of these elements must be different.
to make these unique client sockets use a port assigned by the OS and so you can have more than one client connected to a server and 1 client machine can have more than 1 open socket.
here is a print out from netstat (an IP utility on windows that shows some of my open sockets...
Active Connections
Proto Local Address Foreign Address State
TCP CHEF2:1033 CHEF2:3306 ESTABLISHED
TCP CHEF2:3306 CHEF2:1033 ESTABLISHED
TCP CHEF2:3306 CHEF2:3626 ESTABLISHED
TCP CHEF2:3306 CHEF2:3743 ESTABLISHED
TCP CHEF2:3626 CHEF2:3306 ESTABLISHED
TCP CHEF2:3743 CHEF2:3306 ESTABLISHED
TCP CHEF2:1278 216.71.131.122:22 ESTABLISHED
TCP CHEF2:1694 kw40.primenetwork.net:http CLOSE_WAIT
TCP CHEF2:1863 67.72.120.62:http CLOSE_WAIT
TCP CHEF2:1869 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1870 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1871 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1872 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1875 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1881 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:1884 host16.ipowerweb.com:http TIME_WAIT
TCP CHEF2:3623 216.71.131.122:ftp CLOSE_WAIT
TCP CHEF2:3841 CARTMAN:netbios-ssn ESTABLISHED
at any rate
notice how on my machine (CHEF2) i have a service running on port 3306. i also have three sockets open from my machine acting as a client to the service. you can see it lists these three open sockets to my machine twice each.
at any rate it can tell them all apart from the server end because the port used by the client is different.
to sum up this and the answer given above you don't have to worry about it.

Similar Messages

  • Should i use secure sockets for my whole client/server application?

    Hi,
    I have a client server application, and I want to ensure that the login process is secure (i.e. use secure sockets). but I dont know how to switch back to a normal socket once that is done.
    So I am left thinking that i should just use SSL for my whole application, which can last pretty long. But I would rather not. Is there any other way of doing this?
    or should I just encrypt the login info using MD5 or something like that, then send it over an unsecure socket?
    thanks!

    Hey,
    Are you sure you haven't confused JGSS for JSSE?
    Imagine you have a client-server system and you sometimes want data sent over the wire to be encrypted... JGSS offers you this flexibility; if you a encrypted transmission, run ift through JGSS before transmitting it; if you don't want an encrypted transmission, bypass JGSS and just send the transmission.
    The benefit is the security (encryption) isn't hard-wired into you communications protocol i.e. TLS. JGSS has nothing to do with connections it is just protocol for securing messages, not sending them.
    You would need to establish the secure context but this could be done at startup and persist for the duration of you applicaiton invocation. You perhaps might need to implement a mechanism to identify encrypted messages on the receiving peer (so it knows to attempt decryption).
    Admittedly, kerberos seems like one of those 'inside-joke' things. I've come to realise if you don't have some sort of kerberos realm/server against which to authenticate - you need to swap it out as the underlying mechanism. How this is done I'm not sure yet, but I intend to find out today....further down the rabbit hole I go!
    If I discover anything helpful, I will let you know.
    Warm regards,
    D

  • Client/server application using sockets

    Hi there,
    I'm trying to create a client/server application using sockets where the client has a GUI of a membership application form for some sort of club. Basically, the user will enter their name, address, membership no. etc in to various Jtext fields and then press a JButton to submit these details to the server. The server will then hopefully just dump these details to a text file.
    Can anyone give me any examples, ideas on how to start, links etc.
    Thanks v. much in anticipation,
    Nick

    Take a browse of the tutorial on sockets: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

  • Are there any Client/Server Application (using sockets) design patterns?

    Hi,
    The title of the post nearly says it all. I am searching for different design patterns related with the development of a client/server application. I understand that there must be any different ways on how a client/server application can be developed.
    Regards,
    Sim085
    Disclaimer:
    When I enter in the Socket forum on this site I recieve this message "Thank you for any participation in this forum. Due to a lack of relevant activity, we have decided to archive this forum on June 16, 2006. For future posts on this topic, we suggest you use the Networking forum" and I am not allowed to create a new post! However I can see posts done yesterday! All i did is add the forum in 'my forums'. Does this happen to you people as well?

    Hi Sim085...How are you?
    So look this:
    http://forum.java.sun.com/thread.jspa?threadID=5148926&tstart=75
    I don�t know if is what you want...but I hope in this^^
    Ok man...If you have one example for help you is better.
    [ ]

  • Client/Server application question

    Hey everyone,
    I am trying to exercise on a client/server application. My client application is similar to this one [http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/Code/SocketClient.java]. However this client works like this: it sends text through socket -> receive response from server. I am trying to find a way so that the client can receive and process messages from the server asynchronously. That is the server can send messages anytime (not just as a response to the client) and the client should always be able to receive messages from the served at any time, and not just after it sent something. I believe that multithreading would be the answer, listening to the output stream and sending through the input stream should be run in parallel, but I can't find a way to implement it. Your help is appreciated. Thank you.

    I knew that :-) but how exactly?
    How do I translate this code into two runnable classes which will communicate with the original class and its gui?
    //Send data over socket
              String text = textField.getText();
              out.println(text);
           textField.setText(new String(""));
    //Receive text from server
           try{
           String line = in.readLine();
              System.out.println("Text received :" + line);
           } catch (IOException e){
          System.out.println("Read failed");
                 System.exit(1);
      }

  • Servlet in client/server application?

    hi,
    I am planing to make a client server application( SWING & an OODB), would it be clever to use servlet ( not httpservlet) as midle tier framework?
    If yes , what are the benefits?
    Thanks.

    thanks for responding
    actually my client don't wanna run a separate server application on the hosting machine as it costs too much, so thats why i think there is no other way to achieve the task rather than using servlets.
    please do help me or atleast give me a suggestion. actually i'm developing an internet messenger application. i have developed it using client/server application model in which both (the swing client and the server) uses java sockets to communicate with each other. but now i want to develop the server side of the messenger as servlets. but as far as i know the servlets follow the request/response model. if i follow that model i have to use some sort of client pull after certain amount of time say after five or ten seconds, and this approach does not fulfill my requirements as it would slow the performance if there are hundreds of clients calling the servlet every 5 seconds. thus i want to create persisted connections between the client and the servlet which last for the life time of the user's session. also it is important for the data integrity of the application, so please help me in this matter as i have no other source of guidence in this meany world. i hope you will certainely help me in this matter. please mention that if there are any drawbacks of my approach i mean the persisted connections.
    thanks you a lot
    Best reagrds
    Imran Sarwar.

  • Client/server application under development

    Hi there,
    I've been working on a client/server application that includes chat and whiteboard features. In terms of how the client app communicates with the server app, my initial thought was to just go with xml, until I reached a snag. Everything about chat and almost everything that is accomplished on the whiteboard can be expressed in terms of text or character data; which what makes xml a good candidate for moving the data back and forth from client to server. However, there's one part of the whiteboard feature that can't be converted to just text. The whiteboard has an ImageTool. With it you can select an image (gif,jpg) from your harddrive and load it into the whiteboard. An image is binary data and simply cannot be put into an xml file for transport. At least, that's my understanding. Am I wrong about this?
    So, this poses the questions: "How do other similar applications like MSN Messenger move images around? If they're not using xml as there medium, what are they using? Just plain sockets without any structured medium like xml?"
    Please advise,
    Alan

    You could always Base64 encode the image file content and then put the Base64 in XML.
    I am in the middle of a client-server project and I use XStream ( http://xstream.codehaus.org/ ) to convert Objects to XML automatically. I don't have to do any explicit encoding - XStream does it all for me.

  • Complier error concerning Client Server Application. Error in the server

    Hi I am trying to implement a client server application that will carry out basic calculations. However I am recienving this compiler error within the server class.
    unreported exception java.io.IOException; must be caught or delcared to be thrown.
    The code is pasted below.
    Your help would be much appreciated.
    Kind Regards
    Ridha
    import java.io.*;
    import java.net.*;
    import java.util.Hashtable;
    public class Server
        public static void main(String []args)
            ServerSocket calcServer = null;
            try
                // Create a socket on server
                //ServerSocket ss = new ServerSocket(7);
                calcServer = new ServerSocket(7);
            catch (IOException e)
                System.out.println("Could not listen on port: 7.");
                System.exit(1);
            System.out.println("The Server is Running");
            // When clients connets, make the link and carry on
            Socket clientSocket = null;
            try
             clientSocket = calcServer.accept();
            catch (IOException e)
             System.err.println("Accept Failed");
             System.exit(1);
                // hashtable to manage list of online and offline users
                //Hashtable tOnlineUsers = new Hashtable(10);
                //Hashtable tOfflineUsers = new Hashtable(10);
                // Now start accepting connections from clients in a while loop
                // The server should run in an infinite loop
                 // to get data to and from server
    InputStream in = clientSocket.getInputStream(); < my error is here
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    OutputStream out = clientSocket.getOutputStream();
                    PrintWriter pr = new PrintWriter(out, true);
                while(true)
                    Worker w = new Worker(clientSocket);
                    w.start();
                }   // End of while
            }// End of main()
    }   // End of class

    well, using my superb powers of reasoning and deduction, I can say that this is a lemon entry, watson. the line you kindly highlighted can potentially throw an IOException which you are not dealing with. deal with it

  • Question, in a client server implemention

    Question, in a client server implemention using only basic sockets and datagrams, what happens if a method is being called at the server side while the same method is already being called/running for another client?
    Example:
    Client 1 calls Method 1 at Server Side. Method 1 runs.
    Client 2 calls Method 1 at Server Side. Method 1 is still running for Client 1. Does it create another Thread and runs for Client 2? Or do I have to implement a seperate Thread for each Client myself?

    Thanks!
    Don't want to start a new thread so might as well ask this here,
    Is there a way to pass or at least update the value of a variable from the outside into a Thread that is running? And this value needs to be seen and be the same for all Threads.
    I am thinking of creating new a class that to hold the value I want to update, and passing an object of the class in to the Threads before they runs. Since objects hold reference to the location of the actual object or something like that; people always get worked up over this if I phrase this incorrectly, but I think I got the point across, so that's okay. If I change the value of the object at runtime in the main method, like assign it with a new value according to user input. All the Threads will get the new value right?
    Something like that.
    public class valueToUpdate {
    String value;
    public valueToUpdate(String value) {
    this.value = value;
    public String getValue() {  
    return value;  
    public class Main {  
    public static void main(String[] args) {  
    String str = "abc";  
    valueToUpdate vTU = new valueToUpdate(str);  
    ThreadClass tc1 = new ThreadClass(vTU);  
    Thread thread1 = new Thread(tc1).start();  
    ThreadClass tc2 = new ThreadClass(vTU);  
    Thread thread2 = new Thread(tc2).start();   
    public class ThreadClass implements Runnable {  
    valueToUpdate vTU;  
    public ThreadClass(valueToUpdate vTU) {  
    this.valueToUpdate = valueToUpdate;  
    public void run() {  
    System.out.println(valueToUpdate.getValue());  
    }Okay, something like that. I know I need to add in a TimerTask for ThreadClass too for it to run for a certain period. But if I were to ask for user input at the main method while the TimerTask in running, and I change the value of vTU, will the output for both Threads be changed to the value of the user input?
    Or is there a better way to do it?

  • Advanced Client Server Application

    Hi friends .I'm working on a client server project.In this project I must use two OBJECTOUTPUTSTREAM and OBJECTINPUTSTREAM.But in the program one of them lock the program.
    This code a part of from my code.
    input1 and input2 a ObjectInputStream.
    There are two serversocket in the server side.
    Client side got two socket and connected server's two sockets.
    Sockets had an objectoutputstream and an objectinputstream.
    This project about a game .But players can talk to each other.
    input1 send the game move to another player.
    input2 send the chat message to anoyher player.
    But program always wait the input1 after wait input2.As soon as one of the player moves or seend message another side must take it same time
    I can't do this.
    do{
    move=*this*.input1.read();
    // this wake for move and lock the program here.program doesn't go down.IT'IS A PROBLEM
    message=(String)*this*.inputi2.readObject();
    }*while*(!str.equalsIgnoreCase("Kapat"));
    I thought very much about it.I think I must use a thing lile listener whitch run as soon as objectoutput write to input.
    I'm waiting for your help.If you show a sample code about this subject I pleased very much.
    Good luck everone.Herkese iyi �anslar.this explanation isn'about code and it's my own language.
    T&Uuml;RK&Ccedil;E
    �nsan�n ana dili gibisi yok.Bu a&ccedil;�klamay� Ba�taki ingilizcede sonra yapt���m i&ccedil;in bu dili bu g&uuml;ne kadar geli�tirip gelen t&uuml;m t&uuml;rk milletinden &ouml;z&uuml;r diliyorum.Amac�m istedi�ime ula�mak ve bu siteyi ziyeret edenlerin % 99 ingilizce kulland��� i&ccedil;in b&ouml;yle yapmak zorunda kald�m.Kusuruma l&uuml;tfen bakmay�n.
    K�sace &ouml;zetlemek gerekirse uygulamamda Farkl� socketler &uuml;zerinden birbirine ba�l� 2 OBJECTINPUTSTREAM ve OBJECTOUTPUTSTREAM var
    bunlar�n ikisindende kar��l�kl� ver aktar�yorum .biri oyun hamlesi ta��mak di�eride mesaj ta��mak i&ccedil;in.Ama bunlardan biri program� blokluyor di�eride orogram inemiyor.Bu sorunu &ccedil;&ouml;zmeliyim.
    do{
    move=*this*.input1.read();
    // Hamleyi beklemeye ba�lad���zaman bir mesaj gelince buraya inmiyor illaki hamleyi bekliyor.
    //Hamle geldikten sonrada bu sefer mesaj� bekliyor hamleyi alm�yorr.Bu sorunu halletmem laz�m.
    message=(String)*this*.inputi2.readObject();
    }*while*(!str.equalsIgnoreCase("Kapat"));
    Listener gibi bir �ey kullan�rsam sorun &ccedil;z&uuml;l&uuml;r san�r�m.Yard�mc� olursan�z minnettar olurum.

    I'll go further than that. I'd say that these days, any time you have any kind of client/server application, the first question you should ask is, is there any pressing reason why we can't just use a web server for the server do all communication over HTTP using a textual serialization mechanism like XML and preferably using REST?
    The documentation and infrastructure for this stuff is so extensive these days, and the potential for repurposing is so great, that going any other way without a good reason is a waste of effort. Even if HTTP/REST/XML isn't an exact fit, it can still be worth it (at least for prototyping) just for the convenience.

  • Problem using the File Dialog Box in a Client/Server application

    I am developping a client-server application using Labview 5.1 . The application on the server acquires data from some instruments and saves it on file, while the application on the clients displayes such acquired data. For doing this I call some routines on the server via the "Open Application vi" (remote connection). All goes well except when I open on the server the "File Dialog Box vi" : in this case the application on the clients is blocked (is blocked the execution of the called vi on the server). Only when
    the File Dialog Box on the server is closed, the execution of the called vi on the server starts again.
    I need to use the File Dialog Box on the server, but I don' t want to stop at the same time
    the clients !!
    I need help for resolving such problem.
    Many thanks in advance !!!

    Hi!
    waldemar.hersacher wrote:
    "It seems that the VIs called by the clients are running in the user interface thread.
    A call to the file dialog box will call a modal system dialog. So LV can't go on executing VIs in the user interface thread."
    Are you sure? I think, that File Dialog, called by LabVIEW File Dialog from Advanced File Functions Palette doesn't blocking any cycles in subVI, which running in UI Thread. Look in my old example (that was prepared for other topic, but may be good for this topic too).
    2 linus:
    I think, you must a little bit reorganize you application for to do this. You must put your File Dialog into separated cycle. This cycle, of course, will be blocked when File Dialog appear on the screen. But other cy
    cle, which responsible for visualization will run continuosly at the same time...
    Attachments:
    no_block_with_file_open_dialog.zip ‏42 KB

  • How to validate a server in client-server application

    I am considering a client server application for a masters project. One of the core requirements for this application would be to ensure that the server could not be replaced. This would be easy to do using public/private keys. The client creates a message and encrypts using servers public key, then sends to the server. The server decrypts, processes, creates response, and encrypts using its private key. This works, however the public and private keys need to be in the source code. It looks like keystores may fix that problem, however the password to the key store would then be required. For this application to be usefull, I need to find a way to embed a password or encryption key in a .classfile in a way that it can not be retrieved by decompiling or parsing for strings. Anyone have ideas on how this could be done, or a different method I could use to guarantee that the response coming from a server process is from my server program and not a fake program?

    More detail. The program is a network license server (not web based). We need a simple license server for internal use, so that we can track usage and limit concurrent users for custom software. We also need some security so that people can not take the software home and use it. We have looked at commercial applications, however they are very expensive and we can not justify the cost since this is for internal software. There are 3 main pieces to a license server, the client libraries, the server, and the key generator. For the license server to be usefull, it should be impossible (or very very difficult) for someone to generate their own keys and add them to the license server. It should also be very difficult for them to create a fake license server that will grant licenses to clients without needing keys. If public/private key encryption is used, then the client would need to know the servers public key and their private key. These keys would need to be compiled into the program, stored in a key store, or looked up at run time from some other resource. The server would need to know its private key, and the clients public key. Since this is internal software, we can limit access to the server software, so it would be ok to compile the keys into the code (not ideal but secure enough for out use). However if I use this program as my Masters project, I would need to figure out a better way to secure it. The generic problem is how to give someone two programs that talk to each other, and be able to ensure that they do not fake one of the programs?

  • Need HELP in JAVA ( client /server application )

    hi there ,
    I need the following codes in java for my client/server application . which i can use to perform certain function on another computer on LAN. This is part of my semester project . I would really appreciate if any one can help me
    ->Open/close the CD-ROM once or in intervals (specified in seconds).
    ->Swap mouse buttons the right mouse button gets the left mouse button's functions and vice versa.
    ->Start optional application.
    ->Play optional sound-file.
    ->Point the mouse to optional coordinates.
    ->Shutdown the system, logoff the user etc.
    ->Mouse can be controlled on the target computer with remote mouse.
    ->Keys (letters) on the keyboard can be disabled.
    ->Increase and decrease the sound-volume.
    ->Listen for keystrokes and send them back to you!
    I would really appreciate if some1 can help me find these codes in java
    thanx
    Alamzaib Shafi
    [email protected]

    Dude, if you did your own homework once in a while you'd be able to handle your own semester project. I hope you fail your class and get kicked out of the program. One less idiot with a diploma competing with us hackers for the tech jobs.
    You are indeed a most worthy recipient of my unemployed angst.

  • Writng-Reading stream through client-server application

    I am developing a client-server application which is the client sends a sentence to the server and the server will convert the sentence from small letters to all capital letters. The problem is when the sentence send by the client contains special character such as Registered Trade Mark or Copyright , the server receive the sentence but the special character has changed to undefined symbol. After the server do the conversion process, the server couldn't send back the sentence because of the undefined symbol. It will make the system hangs.
    I use socket connection to do the process. The system use DataOutputStream object to pass the sentence . The source code is as below:
    Socket clientSocket = new Socket("localhost", 111);
    DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
    BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    sentence = "Stomach-Comfort is the all-natural alternative to over-the-counter products, such as Tums�, Rolaids� and Pepcid AC�.";
    outToServer.writeUTF(sentence + '\n');
    modifiedSentence = inFromServer.readLine();
    System.out.println("FROM SERVER: " + modifiedSentence);
    Any body can help me?

    Well, I think that this would work but I haven't tried it, but you could evaluate the numerical value of each
    character and see if it falls within the range of ASCII fields that you want to convert.
    If not don't convert it.
    So for example,
    for each char in your stream:
    1) get a char's numerical value
    2) If between 97-122 decimal
    convert to the capital (forgot the exact method name)
    3) else
    keep value as it is.

  • Running multiple User Profile Service Applications -- recommendations, pitfalls, etc.

    I have a farm with one WFE, one APP, and one SQL server. The User Profile Service runs on both WFE and APP, the User Profile Sync Service is on the APP server. There is a single User Profile service application running that pulls from 4 different AD
    import sources: two in the US, one in London, and one in Mexico.
    There is a nightly incremental synch.
    There is an issue where the London users need the synch to occur hourly.
    There are some complexities with one of the US sources in that would make it difficult to run the current User Profile service hourly, plus there is a performance concern.
    I'm interested in possibly creating a second User Profile Service Application that reads only from London and runs hourly.
    Beyond creating the User Profile service and scheduling hourly, what should I be concerned about?
    Will I need to (re)create new Audiences based on those from the original User Profile Service App? Run them immediately after User Profiles? Will there be an interruption in access during that gap?
    Recreate custom User Properties?
    Recreate any Forefront modifications?
    New Profile/Sync/Social DBs?
    etc?
    Thanks,
    Scott

    Hi Scott,
    According to your description, my understanding is that you want to use multiple user profile service application.
    Yes, you can do it. Only one user profile application can be configured to work with the Profile Synchronization Instance. If you want more UPS instance, you need to start UPS on different server.
    Here are some similar posts for you to take a look at:
    https://social.technet.microsoft.com/Forums/en-US/c922d0a8-db7f-4bdd-87a2-686c836bf406/is-it-possible-to-have-multiple-user-profile-service-applications-on-a-single-server-farm?forum=sharepointadminprevious
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/c771591b-bff6-4d57-99a1-7d46ca1d9903/multiple-user-profiles-service-applications?forum=sharepointgeneralprevious
    https://social.technet.microsoft.com/Forums/en-US/26da9723-70a5-43a2-a2b5-faebe60dbe1a/is-it-possible-to-have-multiple-user-profile-service-applications-on-a-single-farm?forum=sharepointadminprevious
    Best Regards,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

Maybe you are looking for

  • 9cc: MsiExec.exe Application Error Memory Could Not Be Written on Install

    During installation the following error occurs: 9cc: MsiExec.exe - Application Error The instruction at "0x3ff084a2" referenced memory at "0x00000000". The memory could not be written. Screenshot: http://img196.imageshack.us/img196/724/qterror.jpg I

  • IOS 5 to iOS 6 - will i loose data on my iPhone?

    Hi, I am planning for an official upgrade from iOS 5 to iOS 6, so wondering if i loose my messages and other data from my iPhone. I am not in a position to backup my iPhone as the iTunes is not recognizing my phone, it prompts me to format my phone t

  • Questions about free download Oracle 10g, Developer Suite

    Hi everyone, got some questions.. 1) Is it possible to download free Oracle 10g and Developer suite? is a 30 day license trial or something like that? 2) On windows systems which are the minimun requirements?, for example in a Pentium 4, 512Mb RAM, W

  • Program error trying to open files

    Since upgrading to Mavericks anytime i try to open files by going to file,open it says "Could not complete your request because of a program error".. I have uninstalled and reinstalled and also tried using the cleanup tool but still getting that erro

  • ADF Table refresh odd behaviour: is it a bug?

    Hi, I am using JDev 11.1.2.3.0. I found a strange behaviour of ADF table, that looks like a bug. I am using the following scenario: 1). I have a page with a table on it. The table displays the VO content and all it's columns are filterable. 2). There