Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
for a project for school i need to write a chat program.
what i have so far:
database users(Username, Password, IPAddress, onlineStatus)
loginform
mainChatForm
registerForm
im able to connect to the database, register users, check online users,...
but now coms the tricky part and here is where im lost. I now need to write the chatprogram itself. i found some tutorials on the internet but they all use server-client. I dont what to do this i want to make it p2p.
i understand i still need to use the serversocket-socket thing. thats why i keep the users IP in the database.
i need some guidance on how to start to build the chat part of my project.
if someone could help me that would be great.
Thanks
DenTilloZie
If I understand correctly, you will need a central server that holds all of the login information, status of users, and their IP addresses. Users can register their IP address at login time.
In order to initiate a chat with somebody, a user will browse the list of online users on the central server, fetch the IP address of the person they want to communicate with, and then make a direct P2P connection to them.
Everything you need to know about actually implementing this is in the API or stackoverflow. If you have more specific questions about implementation you should probably make another more specific question.
If i'm not wrong, you can make two threads. One holds a server socket and the other a client socket. The server thread will be listening for new messages from the other peer, while the user thread, can be used to send new messages.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I built up my server for my app which is running on Android. And i will hear some opinions from you if the setup is acceptable or complete wrong. So the architecture works like request-respone.
The user will log-in, every app start and will get a new session id.
The client and the server does not have a keep-alive connection. The connection is getting cut every request. For every command on the server, the session id need to get checked first, and then the command or request can be calculated. After everything is done the connection will cut. I was thinking about something that the connection will be held to the server and this gives me the possibility to send from the server some data directly to the client. This could have many usages. But on the other hand its not thread "able". Because i will have to synchronize the socket access and share 1 socket object between all classes and activity, this isnt in my opinion a good way. But am still wondering how other apps or online games could sent data or messages directly to the client. This means that a connection is held. I think that they doing it seperated in a service or something like this. This a new problem im facing. I could use firebase cloud messaging, but this is very slow when more as 100 threads are running on the server. A better solution where, to code a second server program, which is running seprated from the main server and keeps a connection to the client. This would be my solution.
What i just want to know if my architecture is good to go or its a bad idea.
In my opinion, opening and closing the connection is a good practice, because the connection is relatively an expensive resource.
So, I would say that yes, you're good to go with the architecture that you currently have implemented.
Open connection
Execute operation
Close connection
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i wish to add a functionality to my website that is to send a pop up message which i've typed, to all online users . i am able to get user id's of all online users. how could i send message in a jquery pop up to all users. Any one please give me an idea..
The solution to this requires 3 components:
First you need to make sure that whatever is typed is sent to the server. The easiest way is just via an Ajax call whenever you're done typing (or hit a button)
Secondly, you'll have to store the message(s) on the server including what users you've already distributed the message to. This can be just in memory on the server or in a database or file.
Lastly, each of the participating users will have to have a mechanism for retrieving the messages. The easiest way is just to have an Ajax call every 10 seconds for instance which asks the server if there are new messages. If there are they are returned and displayed in a popup.
The server can then mark the message as being sent to that user as well as keep a list of users that are active.
Note both the Ajax communications could be replaced with websocket connections if you want ultimate performance, but they are somewhat harder to set up, so I'd only recommend that if you have many users or many messages.
You can simply write an asynchronous script, that runs in the background, requesting from an API, and if it gets some valid response from API, you can popover a message via jQuery!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have gone through resources on building chat application using socket programming in java. In every implementation people try to make a server which runs in infinite loop, accepting the connections from client and creating a separate thread for handling the chat.
I want to make a chat application in which a new dialog/chat window pops when someone wants to chat with me (on client side). But the catch is that i have only one socket through which i am connected to server. all the messages has to be sent through this streams, currently i am thinking of some adhoc approaches for directing output to different client windows but i am sure that there must be some elegant way to do this.
If you want to use a single socket connection per client, then all communication should be multiplex over that connection, which means that you need to develop a protocol on top of socket streams between your server and a client. A protocol is a set of rules. For example, clients may issue commands and server respond to them, like one command, one response. The commands and responses need to be marked and separated somehow from each other, perhaps you want to add an identifier and a length of a message and then refer to that message.
Various systems use different protocols.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
My problem is the following, I have two servers from which I have to transfer files, in both directions. The transfer is triggered by a file creation event (on respective sides). The problem is one server has a public IP, the other one doesn't.
I have implemented a socket client that sends a file over a socket, and a socket server which receives and saves it. (Working part)
My questions are : How to keep the socket 'alive' and send some data to the client after a file-system event occured on the server-side ? (Can the server call the client without knowing it's public IP ?)
Can I achieve this with socket technology or should I go for something else like RMI ?
The problem I see is not really an implementation issue. The problem is that you want to keep the client without a fixed address. If you had a fixed IP, I suppose there would be no problem. Right? As you probably understand there is no easy way for a computer to be called without having an address.
An option would be to use an middle solution, wrapping your non-fixed IP with a DNS able to refresh. You could use a service like dyndns to get a domain name which will actually redirect each packet to the real IP. Your router would have to be configured accordingly in order to refresh the IP to the dyndns servers each time it changes.
Another option, would be to use the websockets paradigm which now is part of HTML5. This way, the server would be able to push content to the client whenever he wanted it.
All of the above solutions depend heavily on your detailed scenario and I cannot by anyway guarantee that what I suggest is the best solution. Actually, I would strongly suggest to get a fixed IP which is a lot costless and cleaner solution than the ones I describe.
Hope I helped!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I've got the login name of my computer using System.getProperty("user.name"). However, I need the logins of other computers whose IPs I've already got using InetAddress. How do I do it? Displaying the System. properties of all the IPs doesn't display their login names.
Thanks in advance!
All the PCs run on Linux.And I'm looking for the currently logged in user on other machines on the LAN.
I'm pinging all the machines on my LAN to see if a machine is alive. I get it's IP and I want to get its login name as well.
If you were able to do this "out of the box", this would be a huge security hole in the system. Just think about it. And then we don't even get to the problem of multiple users logged in on the machines.
So without further clarification this question is just too vague.
You can actually log on to the machines in a secure way using ssh, for example, and query the list of logged in users. You need to generate ssh keypairs and use some Java terminal library that can do the login programmatically and issue commands for you.
We actually have a product that works like this (for different purposes), and we use a 3rd party SSH library to do the hard work for us.
Or, as an alternative, you can implement and install your own "logged-in-users" daemon that you can connect to, perhaps install it as a web application, but then again, you need to use proper authentication to make your service safe to use. This latter solution however requires that an application or at least a web server is running on each machine that you want to query.
The best possible solution would be to install a software that will listen to a fixed port on the machine. Once you have the machine's address, the program can gather the information and send it back. Other than that, there's no such feature that exists, for various and obvious reasons.
However, even this solution does not guarantee that there will be a listening socket on the listed IP (the software is not guaranteed to be running), so without more information about what exactly you are trying to do, this answer is as vague as the question.