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?
Similar Messages
-
How to run a swing based client server application in web?
hi ,
wat hav 2 do to run a swing based client server application in web?Swing applications run on the client only. You have two basic options:
1) turn the app into an applet so it can run inside the browser (but still on the client)
2) use webstart to allow the swing application to automatically install on the client from your server. -
Please tell me how to use the Simple bluetooth client server example.
Hi i used the simple bluetooth client server example in labview 7.1. Iam getting an error saying your system does not support the network operation. I have following doubts also.
1. Should i pair the device before running the labview.
2. Should i enable the file transfer wizard in the software given with the bluetooth adapter.
Please help
Thank you
R.Prem kumar
09940446193Hi R.Prem,
Could you please let me know what error code is associated with this error message? Also could you please provide a description of the setup you are currently using? Thanks!
Best regards,
Steven -
How to validate Email Address in HTML DB Application
Hi,
I have delevoped one Employee Login Details form in HTML DB. But i am unable to validate that email address as i find html db is not supporting String functions like indexOf(char c), substring(int) ect. So please can anybody help me to know how to validate email address that it has @ and . symbol or not.
Thanks in advance.user529382,
You may be able to use Regular Expressions instead, if you do a search in this forum for 'regex' you should find a few hits.
While I agree that using a regular expression is a great way to verify that the user has entered an email address that conforms to the regular expression rules, it is still nothing more than that....conforming to the regular express rules.
The only way to 100% confirm that an email address is 'valid', is to actually send an email to it, so what I tend to do is to get the user to enter their email twice (in a user registration screen for example), that way you can minimize the chance of 'typos', then send out a 'verification email' that the user has to click a link on to verify they have received it (I'm sure you've seen this type of system before), only when the confirmation is received would I then make the account 'active'.
Hope this helps. -
How to copy a file from Client to Application Server
Hello,
My requirement is user selects a file from Browse button on oracle form - this location is on client side, and have to copy this file on Application server.
I tried using webutil_file.copy_file function but it gives error - copy_file is not a procedure or is undefined.
There is another way of Client_to_AS but it needs some changes in configuration files of webutil, which is not allowed in our scenario.
Source - client machine resident file
Target- Application server disk location
So can any one help in this regard?Hi Francois,
Thanks for your suggestion, actually i didnt want to use Client_to_As as client doesnt want to make any changes in any configuration files, no matter how small the change is.
Anyways we are able to successfully copy the file using Client_to_AS, but one thing that i couldn't understand is why was our webutil_file.copy_file function failing?
Any hint about this?
Thanks!
Avinash.
Pune- India. -
How to Pass a BufferedImage? Client - Server
Please Help!
I've been trying to figure out how to send a BufferedImage from my client program to the server program. I'm using a socket to create the connection. The client draws into a BufferedImage and then it is sent to the server to be saved as a JPG file. I've been able to create the image if I do it locally but since a BufferedImage is not serializable I can't do this the same way with the server. So how do I get my BufferedImage from the client to the server in a manner that I can then save it as a JPG on the server? Code examples would be very much appreciated!!!
Thanks!
RyanI guess I'm not understanding what your saying. I just need a way to get what the user draws into a jpg on the server. I have been using sockets and streams but nothing I try really seems to work. Right now I am doing this:
Client:
Socket client = new Socket( InetAddress.getByName( "localhost" ), 5000 );
ObjectOutputStream output = new ObjectOutputStream( client.getOutputStream() );
ObjectInputStream input = new ObjectInputStream( client.getInputStream() );
try {
ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( imageOut );
imageOut.flush();
encoder.encode( sig.getImage() );
byte[] image = imageOut.toByteArray();
output.writeObject( image );
Server:
public void runServer() {
ServerSocket server;
Socket connection;
try
server = new ServerSocket( 5000, 100 );
while ( true ) {
connection = server.accept();
output = new ObjectOutputStream(
connection.getOutputStream() );
input = new ObjectInputStream(
connection.getInputStream() );
ObjectOutputStream toFile = new ObjectOutputStream(
new FileOutputStream( f ) );
ByteArrayInputStream inStream =
new ByteArrayInputStream( (byte[]) input.readObject() );
JPEGImageDecoder decoder =
JPEGCodec.createJPEGDecoder( inStream );
BufferedImage sigImage = decoder.decodeAsBufferedImage();
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder( toFile );
encoder.encode( sigImage );
toFile.flush();
output.close();
input.close();
connection.close();
toFile.close();
I imagine I have very ugly looking code here but I've been trying to make something work. My code does create the file but it is not a recognizable JPG file.
Ryan -
How to validate users with Novell Directory Server
Hi all, with iAS 6.0 SP3, how i can validate users stored in Novell
Directory Sever?
ThanksHi
I believe iAS is designed to work with iDS which is bundled along
with the SP3 download. Also the directory server which is working with
iAS must be Nortel LDAP Schema compatible and I'm not sure if NDS(Novell
Directory Server) is compatible. What I'm trying to understand is if you
have already registered iAS with NDS and you are having trouble in
accessing the users or if you are having trouble in the installation.
Raj
Josep Maria Camps Riba wrote:
Hi all, with iAS 6.0 SP3, how i can validate users stored in Novell
Directory Sever?
Thanks -
How to construct a URL in client-server model
i wrote a prog, i use jdbc-odbc. URL="jdbc:odbc:filename",it runs very well while all on the SAME computer installed.
but if prog installed on a server and i work on a client-machine, it does'nt work with wrong message like: can not write to file because writesecurty and so on .
i guess i should give another url in form as: hostname + portnumber instead of the old one. is it true?
if yes, how can i get the portnumber of the server?
what else ground could it be?
has anybody experience with this topic, thanks a lot in advanceYou must configure ODBC on the machine where the program is running to refer to the database on the remote system. Don't know how you would do that, it depends on the database and its ODBC driver. If possible, get a JDBC driver for your database and use it instead of JDBC-ODBC.
-
Download text file from application server to client server.
Hi all,
I am facing a format issue while downloading text file from application server to the client machine.
The issue is that, say I have 6 to 10 lines in my text file in application server. but when i store it on the hard drive,
it shoes all the data in a single line. Where as i need to download data in same format as in application server.
Awaiting for your responses.
Regards,
JoseHi,
If we want to upload file data from the application server to the internal table, there is no function module or class static method which we can use, we must wirte the code by ourselves.
1. For the file data which has no seperator between field columns.
PARAMETERS p_file TYPE dxfile-filename.
START-OF-SELECTION.
OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
DO.
READ DATASET p_file INTO gds_data.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND gds_data TO gdt_data.
ENDDO.
CLOSE DATASET p_file.2. For the file data which has tab separator between field columns.
DATA: gds_field_split type gts_data.
FIELD-SYMBOLS: <fs_field> TYPE gts_data.
PARAMETERS p_file TYPE dxfile-filename.
START-OF-SELECTION.
OPEN DATASET prf_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
DO.
READ DATASET p_file INTO gds_field.
SPLIT gds_field AT cl_abap_char_utilities=>horizontal_tab
INTO TABLE gdt_field_split.
LOOP AT gdt_field_split into gds_field_split.
gdf_index = gdf_index + 1.
ASSIGN COMPONENT gdf_index OF STRUCTURE
gds_data to <fs_field>.
IF sy-subrc = 0.
<fs_field> = gds_field_split.
ENDIF.
ENDLOOP.
APPEND gds_data TO gdt_data.
ENDDO.
CLOSE DATASET p_file.
Thanks & regards,
ShreeMohan -
How to delete the workbench client server name in FDM
Hi Gurus
How to delete/change the workbench client server name in FDQM?
regards
SarillaOK, I understand now. You are referring to the Load Balance Server Group. Yes, this can be done:
a) Browse to Oracle\Middleware\EPMSystem11R1\Products\FinancialDataQuality\SharedComponents\Config
b) Locate the LoadBalanceServerGroups.xml file
You can delete this file. The next time the workbench is launched it will ask you to set the load balance server group again and will create this file again. -
How to issue print command from report/form server to client printer on web
1) We have a client server application which is to be deployed on the web environment. The reports generated in our application are having a destination type as File. These reports are printed after applying some print format (escape sequences) which are passed on to the printer programmatically at runtime while printing.
Now when this application is shifted on to the Application server (Forms server & Reports Server )in web environment ,the report outputs would be generated in the application server as against the client in client server environment as the report server is on the application server.
Now while printing/accessing the report the output file will not be available to the client unless it is pushed on to the client side from the server . I am able to see reports in pdf/html output but in this case layout of my reports gets changed and I dont want to change my layouts or reformat my report layouts.
How do I redirect the report output from the application server on to the client within the D2k context and then execute print commands?
Note: In this case we want to use both DMT and Laser printing. Also note that we use escape sequences to adjust reports in desired printing papers.
2) We have second set of reports which we call as document because these are printed after capturing data from 'Form' using text_io utility (please note that for these documents we are not using any Report 6i functionality)and we print it from file using printing mechanism as mentioned above. These are working well in client server application. We adopted this methodology for getting better performance (in terms of speed as database server and network traffic is not involved) of printing. But now we are converting our application for web, we are finding it difficult how to capture Form's data from browser to client's machine and then executing printing commands which are stored in our application liabrary.
If you help me out by giving some suggestions, I shall be grateful to you.
nullHello
I wonder if you ever solved this problem.
I have a very similar problem with Photoshop CS5 on Mac OSX 10.6 + HP Photosmart C7180.
If I choose "Photoshop Manages Colors" the results are lousy.
If I choose "Printer Manages Colors" the results are OK. not necessarily great.
I believe I have all the correct settings after going through books and web advice (and wasted a lot of paper and ink).
As far as I can see, "ColorSync" is the internal Mac management which is the only option available with "Photoshop Manages Colors" and "Vendor Matching" appears to mean the printer vendor (ie HP) will provide the matching. Either can be selected if "Printer Manages Colors" is used. It seems the type of paper can be set in three different places. if That's all a bit academic as the results are poor regardless.
My wife suggests I buy a new printer - Epson's looking good.
Any words of wisdom would be appreciated. -
Hello. I would like to write async tcp client and server. I wrote this code but a have a problem, when I call the disconnect method on client or stop method on server. I can't identify that the client or the server is no longer connected.
I thought I will get an exception if the client or the server is not available but this is not happening.
private async void Process()
try
while (true)
var data = await this.Receive();
this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
catch (Exception exception)
How can I determine that the client or the server is no longer available?
Server
public class Server
private readonly Dictionary<IPEndPoint, TcpClient> clients = new Dictionary<IPEndPoint, TcpClient>();
private readonly List<CancellationTokenSource> cancellationTokens = new List<CancellationTokenSource>();
private TcpListener tcpListener;
private bool isStarted;
public event Action<string> NewMessage;
public async Task Start(int port)
this.tcpListener = TcpListener.Create(port);
this.tcpListener.Start();
this.isStarted = true;
while (this.isStarted)
var tcpClient = await this.tcpListener.AcceptTcpClientAsync();
var cts = new CancellationTokenSource();
this.cancellationTokens.Add(cts);
await Task.Factory.StartNew(() => this.Process(cts.Token, tcpClient), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
public void Stop()
this.isStarted = false;
foreach (var cancellationTokenSource in this.cancellationTokens)
cancellationTokenSource.Cancel();
foreach (var tcpClient in this.clients.Values)
tcpClient.GetStream().Close();
tcpClient.Close();
this.clients.Clear();
public async Task SendMessage(string message, IPEndPoint endPoint)
try
var tcpClient = this.clients[endPoint];
await this.Send(tcpClient.GetStream(), Encoding.ASCII.GetBytes(message));
catch (Exception exception)
private async Task Process(CancellationToken cancellationToken, TcpClient tcpClient)
try
var stream = tcpClient.GetStream();
this.clients.Add((IPEndPoint)tcpClient.Client.RemoteEndPoint, tcpClient);
while (!cancellationToken.IsCancellationRequested)
var data = await this.Receive(stream);
this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
catch (Exception exception)
private async Task Send(NetworkStream stream, byte[] buf)
await stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
await stream.WriteAsync(buf, 0, buf.Length);
private async Task<byte[]> Receive(NetworkStream stream)
var lengthBytes = new byte[4];
await stream.ReadAsync(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
var buf = new byte[length];
await stream.ReadAsync(buf, 0, buf.Length);
return buf;
Client
public class Client
private TcpClient tcpClient;
private NetworkStream stream;
public event Action<string> NewMessage;
public async void Connect(string host, int port)
try
this.tcpClient = new TcpClient();
await this.tcpClient.ConnectAsync(host, port);
this.stream = this.tcpClient.GetStream();
this.Process();
catch (Exception exception)
public void Disconnect()
try
this.stream.Close();
this.tcpClient.Close();
catch (Exception exception)
public async void SendMessage(string message)
try
await this.Send(Encoding.ASCII.GetBytes(message));
catch (Exception exception)
private async void Process()
try
while (true)
var data = await this.Receive();
this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
catch (Exception exception)
private async Task Send(byte[] buf)
await this.stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
await this.stream.WriteAsync(buf, 0, buf.Length);
private async Task<byte[]> Receive()
var lengthBytes = new byte[4];
await this.stream.ReadAsync(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
var buf = new byte[length];
await this.stream.ReadAsync(buf, 0, buf.Length);
return buf;Hi,
Have you debug these two applications? Does it go into the catch exception block when you close the client or the server?
According to my test, it will throw an exception when the client or the server is closed, just log the exception message in the catch block and then you'll get it:
private async void Process()
try
while (true)
var data = await this.Receive();
this.NewMessage.Invoke(Encoding.ASCII.GetString(data));
catch (Exception exception)
Console.WriteLine(exception.Message);
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
By the way, I don't know what the SafeInvoke method is, it may be an extension method, right? I used Invoke instead to test it.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to list IP address from client on the Server (TCP/IP CLIENT SERVER COMMUNICATION)
Excuse me,
In this project I want to ask how to add list IP from client that connect to server.
I have edited slightly the project.
'SERVER
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Reflection
Public Class ServerForm
Private _Listener As TcpListener
Private _Connections As New List(Of ConnectionInfo)
Private _ConnectionMonitor As Task
Private Sub Button_Checked(sender As System.Object, e As System.EventArgs) Handles StartStopButton.CheckedChanged
If StartStopButton.Checked Then
StartStopButton.Text = "Stop"
StartStopButton.Image = My.Resources.StopServer
_Listener = New TcpListener(IPAddress.Any, CInt(PortTextBox.Text))
_Listener.Start()
Dim monitor As New MonitorInfo(_Listener, _Connections)
ListenForClient(monitor)
_ConnectionMonitor = Task.Factory.StartNew(AddressOf DoMonitorConnections, monitor, TaskContinuationOptions.LongRunning)
Else
StartStopButton.Text = "Start:"
StartStopButton.Image = My.Resources.StartServer
CType(_ConnectionMonitor.AsyncState, MonitorInfo).Cancel = True
_Listener.Stop()
_Listener = Nothing
End If
End Sub
Private Sub PortTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles PortTextBox.Validating
Dim deltaPort As Integer
If Not Integer.TryParse(PortTextBox.Text, deltaPort) OrElse deltaPort < 1 OrElse deltaPort > 65535 Then
MessageBox.Show("Port number between 1 and 65535", "Invalid Port Number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
PortTextBox.SelectAll()
e.Cancel = True
End If
End Sub
Private Sub ListenForClient(monitor As MonitorInfo)
Dim info As New ConnectionInfo(monitor)
_Listener.BeginAcceptTcpClient(AddressOf DoAcceptClient, info)
End Sub
Private Sub DoAcceptClient(result As IAsyncResult)
Dim monitorinfo As MonitorInfo = CType(_ConnectionMonitor.AsyncState, MonitorInfo)
If monitorinfo.Listener IsNot Nothing AndAlso Not monitorinfo.Cancel Then
Dim info As ConnectionInfo = CType(result.AsyncState, ConnectionInfo)
monitorinfo.Connections.Add(info)
info.AcceptClient(result)
ListenForClient(monitorinfo)
info.AwaitData()
Dim doUpdateConnectionCountLabel As New Action(AddressOf UpdateConnectionCountLabel)
Invoke(doUpdateConnectionCountLabel)
End If
End Sub
Private Sub DoMonitorConnections()
Dim doAppendOutput As New Action(Of String)(AddressOf AppendOutput)
Dim doUpdateConnectionCountLabel As New Action(AddressOf UpdateConnectionCountLabel)
Dim monitorInfo As MonitorInfo = CType(_ConnectionMonitor.AsyncState, MonitorInfo)
Me.Invoke(doAppendOutput, "Server Started")
Do
Dim lostCount As Integer = 0
For index As Integer = monitorInfo.Connections.Count - 1 To 0 Step -1
Dim info As ConnectionInfo = monitorInfo.Connections(index)
If info.Client.Connected Then
If info.DataQueue.Count > 0 Then
Dim messageBytes As New List(Of Byte)
While info.DataQueue.Count > 0
Dim value As Byte
If info.DataQueue.TryDequeue(value) Then
messageBytes.Add(value)
End If
End While
Me.Invoke(doAppendOutput, "Message from IP: " + System.Text.Encoding.ASCII.GetString(messageBytes.ToArray))
End If
Else
monitorInfo.Connections.Remove(info)
lostCount += 1
End If
Next
If lostCount > 0 Then
Invoke(doUpdateConnectionCountLabel)
End If
_ConnectionMonitor.Wait(1)
Loop While Not monitorInfo.Cancel
For Each info As ConnectionInfo In monitorInfo.Connections
info.Client.Close()
Next
monitorInfo.Connections.Clear()
Invoke(doUpdateConnectionCountLabel)
Me.Invoke(doAppendOutput, "Server Stoped")
End Sub
Private Sub UpdateConnectionCountLabel()
ConnectionCountLabel.Text = String.Format("{0} Connections", _Connections.Count)
End Sub
Private Sub AppendOutput(message As String)
If RichTextBox1.TextLength > 0 Then
RichTextBox1.AppendText(ControlChars.NewLine)
End If
RichTextBox1.AppendText(message)
RichTextBox1.ScrollToCaret()
End Sub
Private Sub ClearButton_Checked(sender As Object, e As EventArgs) Handles ClearButton.CheckedChanged
If ClearButton.Checked Then
RichTextBox1.Clear()
End If
End Sub
End Class
Public Class MonitorInfo
Private _listener As TcpListener
Public ReadOnly Property Listener As TcpListener
Get
Return _listener
End Get
End Property
Private _connections As List(Of ConnectionInfo)
Public ReadOnly Property Connections As List(Of ConnectionInfo)
Get
Return _connections
End Get
End Property
Public Property Cancel As Boolean
Public Sub New(tcpListener As TcpListener, connectionInfoList As List(Of ConnectionInfo))
_listener = tcpListener
_connections = connectionInfoList
End Sub
End Class
Public Class ConnectionInfo
Private _monitor As MonitorInfo
Public ReadOnly Property Monitor As MonitorInfo
Get
Return _monitor
End Get
End Property
Private _Client As TcpClient
Public ReadOnly Property Client As TcpClient
Get
Return _Client
End Get
End Property
Private _DataQueue As System.Collections.Concurrent.ConcurrentQueue(Of Byte)
Public ReadOnly Property DataQueue As System.Collections.Concurrent.ConcurrentQueue(Of Byte)
Get
Return _DataQueue
End Get
End Property
Private _Stream As NetworkStream
Public ReadOnly Property Stream As NetworkStream
Get
Return _Stream
End Get
End Property
Public Sub New(monitor As MonitorInfo)
_monitor = monitor
_DataQueue = New System.Collections.Concurrent.ConcurrentQueue(Of Byte)
End Sub
Private _LastReadLength As Integer
Public ReadOnly Property LastReadLength As Integer
Get
Return _LastReadLength
End Get
End Property
Private _Buffer(63) As Byte
Public Sub AcceptClient(result As IAsyncResult)
_Client = _monitor.Listener.EndAcceptTcpClient(result)
If _Client IsNot Nothing AndAlso _Client.Connected Then
_Stream = _Client.GetStream
End If
End Sub
Public Sub AwaitData()
_Stream.BeginRead(_Buffer, 0, _Buffer.Length, AddressOf DoReadData, Me)
End Sub
Private Sub DoReadData(result As IAsyncResult)
Dim info As ConnectionInfo = CType(result.AsyncState, ConnectionInfo)
Try
If info.Stream IsNot Nothing AndAlso info.Stream.CanRead Then
info._LastReadLength = info.Stream.EndRead(result)
For Index As Integer = 0 To _LastReadLength - 1
info._DataQueue.Enqueue(info._Buffer(Index))
Next
'info.SendMessage("Data Diterima " & info._LastReadLength & " Bytes")
info.SendMessage("reply form server: " & info._LastReadLength & " Bytes")
For Each otherInfo As ConnectionInfo In info.Monitor.Connections
If Not otherInfo Is info Then
otherInfo.SendMessage(System.Text.Encoding.ASCII.GetString(info._Buffer))
End If
Next
info.AwaitData()
Else
info.Client.Close()
End If
Catch ex As Exception
info._LastReadLength = -1
End Try
End Sub
Private Sub SendMessage(message As String)
If _Stream IsNot Nothing Then
Dim messageData() As Byte = System.Text.Encoding.ASCII.GetBytes(message)
Stream.Write(messageData, 0, messageData.Length)
End If
End Sub
End Class
'CLIENT
Imports System.Net
Imports System.Net.Sockets
Public Class ClientForm
Private _Connection As ConnectionInfo
Private _ServerAddress As IPAddress
Private Sub ClientForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ValidateChildren()
End Sub
Private Sub ConnectButton_Checked(sender As Object, e As System.EventArgs) Handles ConnectButton.CheckedChanged
If ConnectButton.Checked Then
If _ServerAddress IsNot Nothing Then
ConnectButton.Text = "Disconnect"
ConnectButton.Image = My.Resources.StopServer
Try
_Connection = New ConnectionInfo(_ServerAddress, CInt(PortTextBox.Text), AddressOf InvokeAppendOutput)
_Connection.AwaitData()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Connecting to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ConnectButton.Checked = False
End Try
Else
MessageBox.Show("Invlid IP Server", "Cannt Connect to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ConnectButton.Checked = False
End If
Else
ConnectButton.Text = "Connect"
ConnectButton.Image = My.Resources.StartServer
If _Connection IsNot Nothing Then _Connection.Close()
_Connection = Nothing
End If
End Sub
Private Sub SendButton_Click(sender As System.Object, e As System.EventArgs) Handles SendButton.Click
If _Connection IsNot Nothing AndAlso _Connection.Client.Connected AndAlso _Connection.Stream IsNot Nothing Then
Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(InputTextBox.Text)
_Connection.Stream.Write(buffer, 0, buffer.Length)
End If
End Sub
Private Sub ServerTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles IPTextBox.Validating
_ServerAddress = Nothing
Dim remoteHost As IPHostEntry = Dns.GetHostEntry(IPTextBox.Text)
If remoteHost IsNot Nothing AndAlso remoteHost.AddressList.Length > 0 Then
For Each deltaAddress As IPAddress In remoteHost.AddressList
If deltaAddress.AddressFamily = AddressFamily.InterNetwork Then
_ServerAddress = deltaAddress
Exit For
End If
Next
End If
If _ServerAddress Is Nothing Then
MessageBox.Show("Cannot resolve Server Address", "invalid Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
IPTextBox.SelectAll()
e.Cancel = True
End If
End Sub
Private Sub PortTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles PortTextBox.Validating
Dim deltaPort As Integer
If Not Integer.TryParse(PortTextBox.Text, deltaPort) OrElse deltaPort < 1 OrElse deltaPort > 65535 Then
MessageBox.Show("Port number between 1 and 65535", "invalid Port number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
PortTextBox.SelectAll()
e.Cancel = True
End If
End Sub
Private Sub InvokeAppendOutput(message As String)
Dim doAppendOutput As New Action(Of String)(AddressOf AppendOutput)
Me.Invoke(doAppendOutput, message)
End Sub
Private Sub AppendOutput(message As String)
If RichTextBox1.TextLength > 0 Then
RichTextBox1.AppendText(ControlChars.NewLine)
End If
RichTextBox1.AppendText(message)
RichTextBox1.ScrollToCaret()
End Sub
Private Sub ButtonClear_Click(sender As Object, e As EventArgs) Handles ButtonClear.Click
RichTextBox1.Clear()
InputTextBox.Clear()
End Sub
End Class
Public Class ConnectionInfo
Private _AppendMethod As Action(Of String)
Public ReadOnly Property AppendMethod As Action(Of String)
Get
Return _AppendMethod
End Get
End Property
Private _Client As TcpClient
Public ReadOnly Property Client As TcpClient
Get
Return _Client
End Get
End Property
Private _Stream As NetworkStream
Public ReadOnly Property Stream As NetworkStream
Get
Return _Stream
End Get
End Property
Private _LastReadLength As Integer
Public ReadOnly Property LastReadLength As Integer
Get
Return _LastReadLength
End Get
End Property
Private _Buffer(63) As Byte
Public Sub New(address As IPAddress, port As Integer, append As Action(Of String))
_AppendMethod = append
_Client = New TcpClient
_Client.Connect(address, port)
_Stream = _Client.GetStream
End Sub
Public Sub AwaitData()
_Stream.BeginRead(_Buffer, 0, _Buffer.Length, AddressOf DoreadData, Me)
End Sub
Public Sub Close()
If _Client IsNot Nothing Then _Client.Close()
_Client = Nothing
_Stream = Nothing
End Sub
Private Sub DoreadData(result As IAsyncResult)
Dim info As ConnectionInfo = CType(result.AsyncState, ConnectionInfo)
Try
If info._Stream IsNot Nothing AndAlso info._Stream.CanRead Then
info._LastReadLength = info._Stream.EndRead(result)
If info._LastReadLength > 0 Then
Dim message As String = System.Text.Encoding.ASCII.GetString(info._Buffer)
info._AppendMethod(message)
End If
info.AwaitData()
End If
Catch ex As Exception
info._LastReadLength = -1
info._AppendMethod(ex.Message)
End Try
End Sub
End Class
//ScreenShot server
http://prntscr[dot]com/5t1ol3
//Screenshot client
http://prntscr[dot]com/5t1odj
source: code[dot]msdn[dot]microsoft[dot]com/windowsdesktop/Simple-Multi-User-TCPIP-43cc3b44I have a similar chat application. When the user attempts to connect, instead of sending a simple string, the client sends a serialized object(xml string) with all relevant login and session information, this includes the user's IP address. Once the server
receives said information, depending on the type of TCP broadcast (a custom enumerated type) information from one user may be passed to a single user, or distributed to many users.
If it helps, here is the TCPBroadcast object I use. But in order for your server to understand it, you kind of have to build your server and client somewhat around it.
Option Strict On
Option Explicit On
Option Infer Off
Namespace TCPChat
Public Class TCPBroadcast
Public Property Message As String
Public Property BroadCastTime As DateTime
Public Property DestUser As String
Public Property OriginUser As String
Public Property PasswordHash As String
Public Property BroadcastSourceIP As String
Public Property BroadCastType As TCPBroadcastType
Public Property LoginUserName As String
Public Property FailureReason As String
Public Function XmlEncoding() As String
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(TCPBroadcast))
Dim XML As String = String.Empty
Using memStream As New IO.MemoryStream
Using xmlWriter As New Xml.XmlTextWriter(memStream, System.Text.Encoding.UTF8) With _
{.Indentation = 4, .Formatting = System.Xml.Formatting.Indented}
serializer.Serialize(xmlWriter, Me)
End Using
XML = System.Text.Encoding.UTF8.GetString(memStream.ToArray)
End Using
Return XML
End Function
Public Function ToBinary() As Byte()
Return System.Text.Encoding.UTF8.GetBytes(Me.XmlEncoding)
End Function
Public Shared Function FromBinary(binary As Byte()) As DeserializationResult
Dim xml As String = System.Text.Encoding.UTF8.GetString(binary)
Return FromXML(xml)
End Function
Public Shared Function FromXML(xml As String) As DeserializationResult
Dim DeserializationResult As New DeserializationResult
DeserializationResult.Error = False
Try
Dim deserializer As New Xml.Serialization.XmlSerializer(GetType(TCPBroadcast))
Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(xml)
Using memStream As New IO.MemoryStream(buffer)
DeserializationResult.tcpBroadCast = CType(deserializer.Deserialize(memStream), TCPBroadcast)
End Using
Catch ex As Exception
DeserializationResult.Error = True
DeserializationResult.ErrorMessage = ex.ToString
DeserializationResult.AttemptedXML = xml
End Try
Return DeserializationResult
End Function
Public Class DeserializationResult
Public [Error] As Boolean
Public ErrorMessage As String
Public tcpBroadCast As TCPBroadcast
Public AttemptedXML As String
Sub New()
End Sub
End Class
Public Enum TCPBroadcastType
AdministrativeMessage
AuthenticationFailure
AuthenticationSuccess
ChatBroadcast
CredentialsRequest
Credentials
DisconnectedByServer
KeepAlive
PrivateMessage
ServerMessage
SystemMessage
UnableToProcessRequest
End Enum
End Class
End Namespace
“If you want something you've never had, you need to do something you've never done.”
Don't forget to mark
helpful posts and answers
! Answer an interesting question? Write a
new article
about it! My Articles
*This post does not reflect the opinion of Microsoft, or its employees. -
Distributed system concept, how 2 server link up and serve a client
here are my code...
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Server extends JFrame{
private JTextArea jta=new JTextArea();
public static void main (String[] args){
new Server(); //launch server
public Server(){//construct a server class
getContentPane().setLayout (new BorderLayout());
getContentPane().add(new JScrollPane(jta), BorderLayout.CENTER);
setTitle("Server");
setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
try{
//create a server socket
ServerSocket serverSocket=new ServerSocket(8000); //server scoket
jta.append("Server started" +"........"+'\n');
//listen for a connection request
Socket socket=serverSocket.accept(); //connect client
//create data input and output stream
DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());//input from client
DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());//output to client
while(true){ // while true, server wait user input
jta.append("Server waiting input from client" +"........"+'\n');
Calendar calendar = Calendar.getInstance();
int GMT = calendar.get(Calendar.HOUR_OF_DAY); //time
long totalMilliseconds=System.currentTimeMillis();
long totalSeconds=totalMilliseconds/1000;
int currentSecond=(int)(totalSeconds%60); //GMT seconds
long totalMinutes=totalSeconds/60;
int currentMinute=(int)(totalMinutes%60); //GMT minutes
long totalHours=(totalMinutes/60);
int currentHour=(int)(totalHours%24);
int Hour=(currentHour+8)%24; // GMT HOUR
String c=""; // c for country
int option = inputFromClient.read();//getinput perform country selection
if(option==1){
c="Africa";
if(option==2){
c="Australia";
if(option==3){
c="Adelaide";
if(option==4){
c="Chaina";
if(option==5){
c="Korea";
if(option==6){
c="Chicago";
if(option==7){
c="New York";
if(option==8){
c="Caracas";
if(option==9){
c="Rio De Janeira";
if(option==10){
c="Racife";
if(option==11){
c="Azores";
if(option==12){
c="London";
if(option==13){
c="Paris";
if(option==14){
c="Cairo";
if(option==15){
c="Moscow";
if(option==16){
c="Baku";
if(option==17){
c="Karachi";
if(option==8){
c="Dhaka";
if(option==19){
c="Bangkok";
if(option==20){
c="Tokyo";
jta.append("Client select: " + c +'\n');
switch(option)//read desire destination, and perform calculation, GMT time base on LONDON
case 1:
GMT=currentHour+1;
jta.append("Africa time now is " + GMT+ ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 2:
GMT=currentHour+8;
outputToClient.writeInt(GMT);
jta.append("Australia time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 3:
GMT=currentHour+9;
outputToClient.writeInt(GMT);
jta.append("Adelaide time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 4:
GMT=currentHour+8;
outputToClient.writeInt(GMT);
jta.append("Chaina time now is " + GMT + ":" +currentMinute + ":" + currentSecond +"\n");
break;
case 5:
GMT=currentHour+9;
outputToClient.writeInt(GMT);
jta.append("Korea time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 6:
GMT=currentHour-6;
outputToClient.writeInt(GMT);
jta.append("Chicago time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 7:
GMT=currentHour-5;
jta.append("New York time now is " + GMT + ":" +currentMinute + ":"+currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 8:
GMT=currentHour-4;
outputToClient.writeInt(GMT);
jta.append("Caracas time now is " + GMT + ":"+ currentMinute + ":"+currentSecond +"\n");
break;
case 9:
GMT=currentHour-3;
outputToClient.writeInt(GMT);
jta.append("Rio De Janeiro time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 10:
GMT=currentHour-2;
outputToClient.writeInt(GMT);
jta.append("Recife time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 11:
GMT=currentHour-1;
outputToClient.writeInt(GMT);
jta.append("Azores time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 12:
GMT=currentHour;
outputToClient.writeInt(GMT);
jta.append("London time now is " + GMT + ":"+ currentMinute + ":" + currentSecond +"\n");
break;
case 13:
GMT=currentHour+1;
outputToClient.writeInt(GMT);
jta.append("Paris time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 14:
GMT=currentHour+2;
outputToClient.writeInt(GMT);
jta.append("Cairo time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 15:
GMT=currentHour+3;
outputToClient.writeInt(GMT);
jta.append("Moscow time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 16:
GMT=currentHour+4;
jta.append("Baku time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 17:
GMT=(currentHour+5)%24;
jta.append("Karachi time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 18:
GMT=(currentHour+6)%24;
jta.append("Dhaka time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 19:
GMT=(currentHour+8)%24;
jta.append("Hong Kong time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 20:
GMT=(currentHour+9)%24;
jta.append("Tokyo time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
}//end switch
//export HOUR, minute,second to client side
outputToClient.writeInt(GMT);
outputToClient.writeInt(currentMinute);
outputToClient.writeInt(currentSecond);
jta.append("Option Found "+ c +'\n');
catch(IOException ex){
System.err.println(ex);
}//end constructor
}//end server class
//server 2
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Server2 extends JFrame{
private JTextArea jta=new JTextArea();
public static void main (String[] args){
new Server(); //launch server
public Server2(){//construct a server class
getContentPane().setLayout (new BorderLayout());
getContentPane().add(new JScrollPane(jta), BorderLayout.CENTER);
setTitle("Server");
setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
try{
//create a server socket
ServerSocket serverSocket1=new ServerSocket("127.0.0.2",8001); //server scoket
jta.append("Server2 started" +"........"+'\n');
//listen for a connection request
Socket socket=serverSocket1.accept(); //connect client
// Socket socket1=serverSocket.accept();
//create data input and output stream
DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());//input from client
DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());//output to client
while(true){ // while true, server wait user input
jta.append("Server waiting input from client" +"........"+'\n');
Calendar calendar = Calendar.getInstance();
int GMT = calendar.get(Calendar.HOUR_OF_DAY); //time
long totalMilliseconds=System.currentTimeMillis();
long totalSeconds=totalMilliseconds/1000;
int currentSecond=(int)(totalSeconds%60); //GMT seconds
long totalMinutes=totalSeconds/60;
int currentMinute=(int)(totalMinutes%60); //GMT minutes
long totalHours=(totalMinutes/60);
int currentHour=(int)(totalHours%24);
int Hour=(currentHour+8)%24; // GMT HOUR
String c=""; // c for country
int option = inputFromClient.read();//getinput perform country selection
if(option==1){
c="Africa";
if(option==2){
c="Australia";
if(option==3){
c="Adelaide";
if(option==4){
c="Chaina";
if(option==5){
c="Korea";
if(option==6){
c="Chicago";
if(option==7){
c="New York";
if(option==8){
c="Caracas";
if(option==9){
c="Rio De Janeira";
if(option==10){
c="Racife";
if(option==11){
c="Azores";
if(option==12){
c="London";
if(option==13){
c="Paris";
if(option==14){
c="Cairo";
if(option==15){
c="Moscow";
if(option==16){
c="Baku";
if(option==17){
c="Karachi";
if(option==8){
c="Dhaka";
if(option==19){
c="Bangkok";
if(option==20){
c="Tokyo";
jta.append("Client select: " + c +'\n');
switch(option)//read desire destination, and perform calculation, GMT time base on LONDON
case 1:
GMT=currentHour+1;
jta.append("Africa time now is " + GMT+ ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 2:
GMT=currentHour+8;
outputToClient.writeInt(GMT);
jta.append("Australia time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 3:
GMT=currentHour+9;
outputToClient.writeInt(GMT);
jta.append("Adelaide time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 4:
GMT=currentHour+8;
outputToClient.writeInt(GMT);
jta.append("Chaina time now is " + GMT + ":" +currentMinute + ":" + currentSecond +"\n");
break;
case 5:
GMT=currentHour+9;
outputToClient.writeInt(GMT);
jta.append("Korea time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 6:
GMT=currentHour-6;
outputToClient.writeInt(GMT);
jta.append("Chicago time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 7:
GMT=currentHour-5;
jta.append("New York time now is " + GMT + ":" +currentMinute + ":"+currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 8:
GMT=currentHour-4;
outputToClient.writeInt(GMT);
jta.append("Caracas time now is " + GMT + ":"+ currentMinute + ":"+currentSecond +"\n");
break;
case 9:
GMT=currentHour-3;
outputToClient.writeInt(GMT);
jta.append("Rio De Janeiro time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 10:
GMT=currentHour-2;
outputToClient.writeInt(GMT);
jta.append("Recife time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 11:
GMT=currentHour-1;
outputToClient.writeInt(GMT);
jta.append("Azores time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 12:
GMT=currentHour;
outputToClient.writeInt(GMT);
jta.append("London time now is " + GMT + ":"+ currentMinute + ":" + currentSecond +"\n");
break;
case 13:
GMT=currentHour+1;
outputToClient.writeInt(GMT);
jta.append("Paris time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 14:
GMT=currentHour+2;
outputToClient.writeInt(GMT);
jta.append("Cairo time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 15:
GMT=currentHour+3;
outputToClient.writeInt(GMT);
jta.append("Moscow time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
break;
case 16:
GMT=currentHour+4;
jta.append("Baku time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 17:
GMT=(currentHour+5)%24;
jta.append("Karachi time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 18:
GMT=(currentHour+6)%24;
jta.append("Dhaka time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 19:
GMT=(currentHour+8)%24;
jta.append("Hong Kong time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
case 20:
GMT=(currentHour+9)%24;
jta.append("Tokyo time now is " + GMT + ":" + currentMinute + ":" + currentSecond +"\n");
outputToClient.writeInt(GMT);
break;
}//end switch
//export HOUR, minute,second to client side
outputToClient.writeInt(GMT);
outputToClient.writeInt(currentMinute);
outputToClient.writeInt(currentSecond);
jta.append("Option Found "+ c +'\n');
catch(IOException ex){
System.err.println(ex);
}//end constructor
}//end server2 class
//client class
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Client extends JFrame implements ActionListener{
private JTextField jtf =new JTextField();//text feild for receiving option
private JTextArea jta=new JTextArea();//text area display contents
private JButton btnDownload=new JButton("Download");
//IO stream
private DataOutputStream toServer;
private DataInputStream fromServer;
public static void main(String [] args){
new Client(); //launch client
public Client(){//construct a client class
//display layout
JPanel p=new JPanel();
p.setLayout(new GridLayout(1,3));
p.add(new JLabel("Select file name:"));
p.add(jtf, BorderLayout.NORTH);
p.add (btnDownload);
p.add (new JButton("RESUME"));
p.add(new JButton("STOP"));
jtf.setHorizontalAlignment(JTextField.LEFT);
getContentPane().setLayout(new BorderLayout()); //set borderlayout
getContentPane().add(p, BorderLayout.NORTH);
getContentPane().add(new JScrollPane(jta), BorderLayout.CENTER);
// btnDownload.addActionListener(this);
jtf.addActionListener(this); //perform action
setTitle("Client"); //interface title
setSize(600,300); //interface size
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
try{
//create a client socket
Socket socket=new Socket("localhost",8000);
// Socket socket1=new Socket("127.0.0.2",8001);
jta.append("Client started.....\n" +"your locale time is " + new Date()+ '\n');
fromServer=new DataInputStream(socket.getInputStream()); //initialize get from server
toServer=new DataOutputStream(socket.getOutputStream()); //initialize to server
catch(IOException ex){ //error if server timeout
jta.append(ex.toString()+'\n');
public void actionPerformed(ActionEvent e){ //action perform when user hit enter
String actionCommand=e.getActionCommand();
if(e.getSource() instanceof JTextField){
try{
int option=Integer.parseInt(jtf.getText().trim());//convert text to integer
String c=""; //c for country list
toServer.write(option);//write selection and sent to server
toServer.flush(); //server refresh
int inputFromServer = fromServer.readInt();//initilize read data from server, integer format
//if ...selection to determine the country user desire
if(option==1){
c="Africa";
if(option==2){
c="Australia";
if(option==3){
c="Adelaide";
if(option==4){
c="Chaina";
if(option==5){
c="Korea";
if(option==6){
c="Chicago";
if(option==7){
c="New York";
if(option==8){
c="Caracas";
if(option==9){
c="Rio De Janeira";
if(option==10){
c="Racife";
if(option==11){
c="Azores";
if(option==12){
c="London";
if(option==13){
c="Paris";
if(option==14){
c="Cairo";
if(option==15){
c="Moscow";
if(option==16){
c="Baku";
if(option==17){
c="Karachi";
if(option==8){
c="Dhaka";
if(option==19){
c="Bangkok";
if(option==20){
c="Tokyo";
jta.append("Selected: "+ c +'\n');
int GMT = fromServer.readInt(); //hour import from server
int currentMinute = fromServer.readInt();//minute import from server
int currentSecond = fromServer.readInt();// second from server
//print full time format in JtextArea
jta.append("Time is >>"+GMT+ ":" +currentMinute+ ":" +currentSecond+'\n');
catch (IOException ex){
System.err.println(ex);
}// end if ..true
}// end actiond
}//end client classhere i attach my similar code again, which can compile..
problem is, how to let this server to communicate with each other, if i duplicate my server code. Which mean 2 server.
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Server extends JFrame{
private JTextArea jta=new JTextArea();
public static void main (String[] args){
new Server(); //launch server
public Server()
{//construct a server class
getContentPane().setLayout (new BorderLayout());
getContentPane().add(new JScrollPane(jta), BorderLayout.CENTER);
setTitle("Server");
setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
try{
//create a server socket
ServerSocket serverSocket=new ServerSocket(8000); //server scoket
jta.append("Server started" +"........"+'\n');
//listen for a connection request
Socket socket=serverSocket.accept(); //connect client
DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());//input from client
DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());//output to client
while(true){ // while true, server wait user input
jta.append("Server waiting input from client" +"........"+'\n');
jta.append("Option Found "+ '\n');
catch(IOException ex){
System.err.println(ex);
} -
How can i check the office web app server(wac client) is calling custom WOPI host?
I am getting an error when I testing my wopi host(which is the same as
example) with Office Web app server "Sorry, there was a problem and we can't open this document. If this happens again, try opening the document in Microsoft Word."
1-how can find the log files of this error?
2-how can i check the office web app server(wac client) is calling my WOPI host?
I am not sure about cumunication between owa to wopi host. I actually dont know how to implement checkfile and getfile functions to wopi host for waiting for call back from owa client.
Note:I am sure that office web app server is configured true. Because i test it with sharepoint 2013 and editing and viewing is working well.Hi,
According to your post, my understanding is that
CheckFileInfo is how the WOPI application gets information about the file and the permissions a user has on the file. It should have a URL that looks like this:
HTTP://server/<...>/wopi*/files/<id>?access_token=<token>
While CheckFileInfo provides information about a file, GetFile returns the file itself. It should have a URL that looks like this:
HTTP://server/<...>/wopi*/files/<id>/contents?access_token=<token>
There is a great article for your reference.
http://blogs.msdn.com/b/officedevdocs/archive/2013/03/20/introducing-wopi.aspx
You can also refer to the following article which is about building an Office Web Apps(OWA) WOPI Host.
http://blogs.msdn.com/b/scicoria/archive/2013/07/22/building-an-office-web-apps-owa-wopi-host.aspx
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support
Maybe you are looking for
-
Hi, I have a pdf file that was downloaded into my downloads folder. For some reason, when i click my downloads folder from the dock, the file shows up (in the fan-like display) and I cannot drag it into the trash. When i open the downloads folder in
-
.pages file created in Pages for Mac won't open in Pages for iPad
Just created a pages document on my Mac, saved it to my google drive and when attempting to "open in" from my google drive the file won't open in pages for iPhone or iPad (mini). All versions of Pages are on latest release. Messge reads: Document can
-
Individual pdf files for every page
Hi.. We have a scenario like this. We have around 8000 records in a table and we have to generate a report which has to create 8000 pdf files at a stretch. ( 1 pdf for every row) Please throw some light on this...and let us know how to do this.. Than
-
Macbook Scrolling Problem. Please Help!!
I use Firefox for my web browser and I am having a scolling problem. Every time I am watching a video on Youtube the video window always disappears when I scroll up or down. Is there any way to stop this? Black 13" Macbook Core 2 Duo Mac OS X (10.4
-
WWCTX_API.GET_USER
I created a custom folder and typed following sql in that: SELECT WWCTX_API.GET_USER from dual there was no problem in creating this folder. When i create a worksheet in plus and while running a query, its giving following errors ORA-14551: cannot pe