serversocket

How to close port after using server sockets [closed]

风流意气都作罢 提交于 2019-12-01 03:38:10
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . In my application I create a ServerSocket instance with some port. After I am finished, I close the socket, but when I try to make a new ServerSocket on

Difference between TCP Listener and Socket

核能气质少年 提交于 2019-11-30 12:30:26
问题 As far as I know I can create a server using both TCPListener and Socket, so what is the difference between the two of them? Socket private Socket MainSock; MainSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); MainSock.Bind(new IPEndPoint(IPAddress.Any, port)); MainSock.Listen(500); MainSock.BeginAccept(AcceptConnections, new Wrapper()); TCPListener Int32 port = 13000; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); TcpListener server = new TcpListener

Wi-Fi Direct Android

痞子三分冷 提交于 2019-11-30 07:42:35
I want to transfer files between 2 devices via Wi-Fi Direct. I wanted to do the same thing as in WifiDirectDemo, but I can't transfer data from the group owner to the other device, so I tried this: each time when one of the devices clicks connect, the other device is set as the group owner, so on each connection the device who asks for connection is always the client and can send data. The problem with this is that Android always remembers the first group created and therefore its group owner. In other words, what I did only works the first time unless I go to settings and forget the group

Difference between TCP Listener and Socket

瘦欲@ 提交于 2019-11-30 03:18:27
As far as I know I can create a server using both TCPListener and Socket, so what is the difference between the two of them? Socket private Socket MainSock; MainSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); MainSock.Bind(new IPEndPoint(IPAddress.Any, port)); MainSock.Listen(500); MainSock.BeginAccept(AcceptConnections, new Wrapper()); TCPListener Int32 port = 13000; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); TcpListener server = new TcpListener(localAddr, port); server.Start(); I'm really confused. The two of them listen for connections, so what

How to create a bluetooth server socket in android?

三世轮回 提交于 2019-11-29 21:06:50
问题 I am trying to create a server program that just starts bluetooth, creates a server socket, waits for some device to connect and accepts the connection. The onClick() method starts the bluetooth, then I call the AcceptThread() method to create a server socket and start listening. Then run() is called which accepts a connection. But it is not working. My app just stops. Any idea why? The code is given below: public class MainActivity extends Activity { public BluetoothAdapter mBluetoothAdapter

Server-Client chat program

半腔热情 提交于 2019-11-29 18:17:06
I am writing a server-client chat program. Here is my code SERVER: import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class HelloServer { public final static int defaultPort = 2345; public static void main(String[] args) { int port = defaultPort; try { port = Integer.parseInt(args[0]); } catch (Exception e) { } if (port <= 0 || port >= 65536) { port = defaultPort; } try { ServerSocket ss = new ServerSocket(port); while (true) { try { Socket s = ss.accept(); String response = "Hello " + s

Error message: “Bitmap Image is not valid” on received from Socket

╄→尐↘猪︶ㄣ 提交于 2019-11-29 17:58:26
I'm trying to get a screenshot and send it over the web using ClientSocket and ServerSocket components. I'm having problems when I try to turn the stream received at ServerSocket into a picture again. Error message "Bitmap Image is not valid!" when performing: DesktopForm.imgScreen.Picture.Bitmap.LoadFromStream(ms); I do not know if the problem is in the way sending the image or get in the way. My server code: unit UntThreadDesktop; interface uses System.Classes, System.SysUtils, System.Win.ScktComp, WinApi.Windows, WinApi.ActiveX, Vcl.Graphics, Vcl.Imaging.Jpeg, UntDesktopForm; type

Knock Knock application with server and UI

廉价感情. 提交于 2019-11-29 17:24:21
I am creating a simple Knock Knock application (socket programming) where there is a localhost server and there is a client.the program is simple, the server will tell the knock knock jokes, this is how it's supposed to go, Server: Knock Knock Client: Who's there? Server: Turnip. Client: Turnip Who? Server: Turnip the heat. So that's how the program supposed to go. but the thing is my GUI doesn't show any messages. on my Text area. Here are my codes. The Server: import java.net.*; import java.io.*; public class KnockKnockServer { public static void main(String[] args) throws IOException {

How to make GUI Client to upload file in java

落花浮王杯 提交于 2019-11-29 16:01:26
Please help me I want to make a GUI application which upload a file from client to server. when I click on browse button then file is copy in bytes form because we travel data in bytes on network but when I click on upload button then file cannot upload. import javax.swing.*; import java.awt.event.*; import java.io.*; import java.net.*; class ClientUpload extends JFrame implements ActionListener { JFileChooser fc; JButton b, b1; JTextField tf; FileInputStream in; Socket s; DataOutputStream dout; DataInputStream din; int i; ClientUpload() { super("client"); tf = new JTextField(); tf.setBounds

Wi-Fi Direct Android

时间秒杀一切 提交于 2019-11-29 10:24:44
问题 I want to transfer files between 2 devices via Wi-Fi Direct. I wanted to do the same thing as in WifiDirectDemo, but I can't transfer data from the group owner to the other device, so I tried this: each time when one of the devices clicks connect, the other device is set as the group owner, so on each connection the device who asks for connection is always the client and can send data. The problem with this is that Android always remembers the first group created and therefore its group owner