I am creating an Intra Office Messaging System in Java using client-server architecture. The features I want to implement are: real-time chatting and messaging to a specific user or group of users, file transfer and voice-chat.
I have implemented the server and the client module using which the client can login on the server. I have used DataInputStream and DataOutputStream for this. When user submits username and password, I store them in a single string separated by a semi-colon ";" and then I send this string to server using DataInputStream where I separate them and run a DB query and send appropriate acknowledgement to the client application.
Now I want to implement chatting and messaging. My question is, shall I use the same approach for this? Or is there a better solution? Also, how can I send the message to specific client(s) (client A wants to send message only to client B). While suggesting a solution, please keep in mind that I have to implement voice chat as well (gstreamer) as filetransfer!!!
Also, I maintain an array containing names of all clients who log-in to the server which is used to display the list of logged-in clients to each client.
Firstly, by sending the username and password as a plain-text string, you're practically giving them away freely - anyone with a few basic tools can sniff the username and passwords. You are going to need to read up on cryptography and how you can secure the connections. Java has a built-in cryptography library which makes this very easy to do.
If possible, I would recommend going for an already developed chat protocol like XMPP (Jabber), for which there already exist many free Java library implementations, such as Smack, that will do everything for you. There really shouldn't be any need to re-invent the wheel here unless you are doing this for a school project that doesn't allow any use of external libraries, which would be extremely ambitious in of itself. XMPP has support for text chat, voice chat, and file transfers.
There are also already several fully featured open-source chat clients that you could modify to suite your specific needs. One thing to keep in mind though, is the licensing on open-source projects. Some open-source licenses, like the popular GPL, require that using any part of the open-source project in your project requires that you release the source code for your entire project. This could be extremely disastrous for a corporation, so watch out.
If you still want to start from scratch, then you'll need to implement your own protocol of communication. You'll have to design this yourself, while taking into consideration how you'll incorporate gstreamer and file transfers.
Again, I would recommend at least looking at some already designed protocols, like XMPP, to get some ideas.
Usually, protocols have,
Some data explaining what type of request/response this is. This could be a numeric value stored as a single byte, or some text string like as is done in HTTP
Some more data pertaining to who the message is for. Could be an IP address, username, combination of both, etc. Not necessary if you're doing the communication directly, i.e. not through a middle-man server
The time the request was sent
The data itself
Some sort of encryption. Best initiated after the user was authorized
For example, a really basic protocol could be,
Request type: 1 byte. 1 = text, 2 = voice data, 3 = file transfer, 4 = request for currently logged-in client list
Destination: int (IP address)
Time: long. Best to send this as UTC time, e.g. what System.currentTimeMillis returns
Length of data: int
Data: variable length data, depending on type
Then, for each type of data being sent, you'd implement the data differently,
Text: string as sent by DataStream
Voice: voice data from gstreamer (not sure how gstreamer works)
File transfer:
File name: String as sent by DataStream
Length: long
Data: As read from FileInputStream
List of currently-logged in clients:
Data: as sent by DataStream.writeObject
Good luck
Related
Is it possible to read datastream sent from C++ server program to C++ client over socket connection in java? I have details like port number and server IP.
Or do I need decompile the whole C++ client into Assembly and then somehow translate it into java to do that?
I'm really not sure what kind of data it's transforming, though.. Somebody told me to code HTTP server and run it on my Router but I'm not really sure if that would work?
Here’s the diagrammatic way to look at it.
Server generates data.
it puts it in a packet.
it encrypts the packet.
and sends it over the wire.
It gets to a user’s Computer (= client). (I should be in the control now on..)
(If I could somehow read data at this part?)
The client reads the encrypted packet.
(If I could somehow read data at this part?) (The later, the better :D)
The client decrypts the packet.
(If I could somehow read data at this part?) (The later, the better :D)
The client does something.
As said, the client is .exe file and it's coded using C++. And I don't have source code of it.
All you have to do is define well your application protocol. This is, the format of your data stream. As long as you are using the same format in both ends, it doesn't really matter what language or program you are using. Imagine your browser and the web server. They are both using the same application protocol (HTTP) but they are completely different programs. Even more, there exists different web servers and different browsers.
Then, all you need to do is use the java sockets to listen to some specific port, and use your c++ sockets to write to the specific port. Just make sure you know how the information is "organized".
As the diagram suggests, there is one main server and more than one user application. Server in its database, has maintained a set of feeds for each application.In other words, each application will have a set of unique feeds.
How does the client application receive the feeds from the server ? The only problem that has kept me away from implementing this is, how client will ask the server to send its feeds. Even if the client pokes the server about the feed, how will the server send them or how will the client receive it. One way out could be, the server writes all the feeds to a file and then the client knowing the address of the file parse it extracting the relevant data. But it could be a very long process if the there are many clients connected to the server.
Note: The client application is a desktop application
You probably want to identify the client by a unique user string or by authenticating the user. The most common way for implementing this is probably basic authentication (username/password) or a security string.
Basic Auth:
User enters username/password in the client software which is bundled with the feed request using either POST or HTTP-BA.
Security/Identifier string:
User enters a unique string such as hashed user ID or alike, which the client bundles with the feed request. E.g https://feed.domain.com?identity=fed54bd54ae...
There's plenty of ways to differentiate clients. Imagine what you will do when you go to a store. Do you just stand there, waiting for the cashier to give you something? No, you ask for something. How you implement that is up to you. You can use different ports, different URLs, define the protocol so that the client passes the name or id of the wanted resource when it connects.... Nothing really special here.
I am trying to learn how to make a multiple-client chatting program. Im following the Oracle tutorial on Custom Networking, but its not really what I am looking for. So far, I have no code of my own to share, all of it is copied from the Oracle tutorial and I think pasting it here would be a copyright infringement(??).
link at: http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html+
client code link: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java
anyway, I have the server-client working where the server tells knock knock jokes, the client reads and prints, then the user replies and so on. how would i start to edit it to have the client talk to the other clients directly?
im sorry, i have no background with networking at all. if anyone can direct me to a informative source better suited to my goals i would appreciate it.
as in the Knock-Knock example, each client connects to the server, but they not mutually directly connected.
There is a solution to make a forwarding sever :Arrange each client an id, and clients use id to identify their talking partners.
To do this, you have to modify the client to server data format from a plain string to a tuple like (String,Id). And, when the server receive the data, it parses out the id, get the corresponding client socket and then write the data.
The required level of complexity just went up a notch as your going to need some sort of "interprocess communications" infrastructure to allow client to client communication (possibly via sockets marshalled by the server?)
I know that many has been ask for how to create a SMS server, but there has been been a fragmentation of knowledge because some just ask for a C# or PHP solution. My situation is different:
I need to develop 2 different services:
Receive SMS with a key work of what kind of information the client's client wants, like "FOOTBALL SCHEDULE" and the search in some data-base to send back to the sender's phone something like "12/12 NY X LA at 14:00h \n 13/12 DC X TX at 21:00h";
Client comes to my site and pays for 1000 SMS with message "Merry Christmas to you Girls!" with the possibility to enter the numbers or pick a random set in our own database according to what kind of people he/she wants to inform.
For that I can use:
Delphi or Java for Desktop/Web or Java for Android or PHP for Web;
MySQL or Firebird
A personal server or a Internet 3rd party server;
A SMS API service on the Internet or a personal phone with unlimited SMS sending pack.
So, the options are many. I can use a Android App in a Cell Phone or other kind of App in my PC connected to the Phone via USB. I can also use the Nokia NetBook that comes with a 3G slot and manage it from my App.
I have never made a program to handle any cell phone network services.
What I'd like to know from the unlimited StackOverflow users wisdom is:
Which of these options are the best to practice in the matter of available resources for SMS in these technologies?
Is there any finished community project with these arguments that I can be part of or import any piece of code/knowledge to mine?
Is there an API with these two services already available?
I am trying to avoid to contract a cellphone network provider to do that services. The cost would made it impossible. We are not intend to get a great profit, just to make these kind of services available in my region.
Thank You All!
there are plenty of web to sms gateways available worldwide.
usually they offer a http interface for incoming and outgoing sms.
so the simplest solution would be to find an affordable gateway provider and setup any kind of webserver to listen to the http request from the gateway provider on incoming messages.
this could be done in any environment you're familiar with.
for outgoing messages you would simply call an url of the gateway provider like
http://examplegateway.com/send?msisdn=23443&message=Merry+Christmas+to+you+Girls&secret=somesecrethash
this is easier than to program on the phone directly and usually cheeper, too. at least here in europe.
the contracts to the gateway providers come in as many differenty flavors as there are providers out there. with prepaid, postpaid, bulk-prices, monthly fee, pay-as-you-go you name it.
1 ) IMHO, and for my experience, the option 4 is the best, because this option allows you to have better scalability, and you separate the SMS logic, from you inner logic. Also, you don't need a person for maintain any server.
In the future, maybe you need to create another service, or another app. Using the option 4, you can reuse some code (or only the SMS API). Now you're using Android, but in the future, maybe you wanna create a Java Desktop Client, or iOS, or windows mobile, or.....
2 ) IDK :(...
3 ) IDK 2. I'm from Argentina, and we use a service only available here (Intertron)
How could one go about accessing email without interfering in any way that would be visible to a user with standard email clients such as Thunderbird?
P.S: I've marked this as both java and language-agnostic so the approach can be described in general steps or detailled programatically.
You would like to access the mail server directly over network programmatically. You only need to know the address (URL) of the mail server (usually in flavor of smtp.domain.com), the port number (usually 25) and the login username and password (the one of the existing mail account at the mail server).
In low-level, you need to know socket programming. In Java, there's the java.net.Socket API for this. Also see this tutorial. To communicate with a mail server you need to learn the SMTP or IMAP protocols, depending on what the mail server in question understands, to send/retrieve commands as bytes over the socket accordingly.
In high-level, you can use a more convenient API which doesn't require you to understand the low level specifics (which may be pretty complicated and verbose). In Java, you can use the JavaMail API for this. It has an excellent FAQ with a lot of code examples.